Roblox - How do I check the player's Team?

923 Views Asked by At

I work on a roleplaying game where the player has to mount a radiator in a specific job. Now I want only the plumbers to be able to mount radiators, hence that I work on an item placement system. The only problem I face currently is that even though im in the correct team it still fails to detect me as the correct person. This here is the relevant, full script used.

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)

1

There are 1 best solutions below

0
On BEST ANSWER

you need to check the color e.g:

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)