Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I check if a player is on a certain team?

I've got a server script that puts on a hat if a player clicks the hat, all of the script works perfectly except for the new part that I've added that checks what team the player is on before putting the hat on the player, It outputs no errors, but just does nothing.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Headlamp")

local ClickDetector = script.parent:FindFirstChild("ClickDetector")
game.Players.PlayerAdded:Connect(function(Player)
    print(Player.Name)
end)

local Teams = game:GetService("Teams")
local Hunters = Teams:FindFirstChild("Hunters")

ClickDetector.MouseClick:Connect(function(Player) 

    print('ClickRegistered')

    local Headlamp = script.Parent
    local Playername = Player.Name
    print(Playername)
    local Playeruser = game.Workspace:WaitForChild(Playername)
    local Humanoid = Playeruser:WaitForChild("Humanoid")

    if Playeruser:FindFirstChild("Headlamp") == nil then

        if Playername.Team == Hunters then

        Humanoid:AddAccessory(Headlamp)
        remoteEvent:FireClient(Player)
    end
    end


end)


Could someone tell me why? Thanks!

7 comments

0

put quotes around Hunters on line 24

0

Did the game print "ClickRegistered"? If yes then try adding print function in the if statements to detect where the script stopped. If no then report engine bug :)

0

Didn't work

0

Does print "ClickRegistered", added some other ones and yeah it stops at line 24 where it checks if the player is on the team

0

is it because you are calling Playername? let's say its your username it would call CheeseBallGuy11.Team

0

Yeah playername is just the username

0

if player.Team == game.Teams["TEAM NAME"] then ... end || In your case, it would be game.Teams.Hunters 

1 answer

✓ Accepted answer

Player.Name Doesn't have a property called Team. To call the team use this

Player.Team

This discussion is preserved as it was. New answers, comments, and votes are closed.