Roblox如何检测玩家的队伍

我正在制作一个Roblox游戏,我需要以某种方式检测玩家的队伍。 我的代码目前看起来是这样的:

script.Parent.Touched:Connect(function(part)
    local plr = part.Parent.Name
    if (game.Players:FindFirstChild(plr).Team == "Police") then
        ....
    end
end)

当我碰到那个部分时(它是一个看不见的墙),它给我一个错误:Workspace.Part.Script:3: attempt to index a nil value

我做错了什么?

编辑:我发现它找不到我的名字在game.Players中,因为现在我尝试过了:

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:FindFirstChild(hit.Parent.Name)
    if (plr.Team == "Police") then
...

现在我得到Workspace.Part.Script:3: attempt to index local 'plr' (a nil value)

编辑2:现在我尝试打印plr(game.Player:FindFirstChild(hit.Parent.Name))它是'Miniller'而不是'Miniller',现在我没有收到任何错误,但下面的代码也没有任何作用...

点赞
用户10376523
用户10376523

我通过不使用变量和不使用 "Police" 来解决它,它是 game.Teams.Police 的游戏,所以代码如下:

if (game.Players:FindFirstChild(hit.Parent.Name).Team = game.Teams.Police
...
2019-02-02 11:18:55