08:10:58.779 ServerScriptService.TimerScript:17:尝试将实例与字符串 - 服务器 - TimerScript:17 连接起来?

08:10:58.779 ServerScriptService.TimerScript:17: attempt to concatenate Instance with string - Server - TimerScript:17?

我正在努力让它打印出顶级玩家的名字,但它的输出在标题上打印了错误。

代码如下:

local highest = 0
local mostvote = 0

while true do
wait(10)
local TopPlayer
local TopCash = 0

for i, plr in ipairs(game:GetService("Players"):GetChildren()) do
    local kills = plr.leaderstats.Kills.Value
    if kills >= TopCash then
        TopPlayer = plr
        TopCash = kills
    end
end

print(TopPlayer.." Got the most kills so "..TopPlayer.Team.." wins!")

for i, plr in ipairs(game:GetService("Players"):GetChildren()) do
    local kills = plr.leaderstats.Kills.Value
    kills.Value = 0
end

end
print(TopPlayer.." Got the most kills so "..TopPlayer.Team.." wins!")

错误告诉您发生了什么:您有一个实例,您正试图向它添加一个字符串,但它不知道如何处理它。 TopPlayer 是一个 Player instance, and you probably want to print out their name. So instead of using the Player instance directly, you should probably use their Name or their DisplayName in the message. Similarly, TopPlayer.Team is a Team 实例,您可能还应该打印它的名称。

print(TopPlayer.Name .." got the most kills so " .. TopPlayer.Team.Name .. " wins!")