Roblox - 如何检查玩家的队伍?

我正在制作一个角色扮演游戏,玩家必须在特定职位上安装暖气片。现在我希望只有管道工能够安装暖气片,因此我正在开发一个物品放置系统。我目前面临的唯一问题是,即使我在正确的队伍中,它仍然无法检测我是否是正确的人。 这是使用的相关完整脚本

script.Parent.Event.OnServerEvent:connect(function(player)
if player.Team == game.Teams.Haustechniker then
    local backpack = player:WaitForChild("Backpack")
    local character = player.Character or player.CharacterAdded:Wait()
    local function purgeLaunchers(container)
        for _, item in pairs(container:GetChildren()) do
            if item:IsA("Tool") and item.Name:match("Abdeckvlies") then
                item:Destroy()
                script.Parent.Part.Transparency = 0
                script.Parent.Event:Destroy()
                script.Parent.Text:Destroy()
                script.Parent.Range:Destroy()

            end
        end
    end
    purgeLaunchers(backpack)
    purgeLaunchers(character)
end

end)

点赞
用户14354572
用户14354572

你需要检查颜色,例如:

local function checkTeam(player)
    if player.TeamColor ~= nil then
        if player.TeamColor == 'Red' then
            return 'Red'
        elseif player.TeamColor == 'Orange' then
            return 'Orange'
        end
    else
        return false
    end
    return nil
end

game.Players.PlayerAdded:Connect(function(player)
    if not checkTeam(player) then return end
    if checkTeam(player) == 'Red' then
        print(player.Name .. ' is in the red team')
    end
end)
2020-09-28 14:28:31