Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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!

0
put quotes around Hunters on line 24 OMGgaming89 2 — 3y
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 :) tuanorn 6 — 3y
0
Didn't work CheeseBallGuy11 12 — 3y
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 CheeseBallGuy11 12 — 3y
View all comments (3 more)
0
is it because you are calling Playername? let's say its your username it would call CheeseBallGuy11.Team OMGgaming89 2 — 3y
0
Yeah playername is just the username CheeseBallGuy11 12 — 3y
0
if player.Team == game.Teams["TEAM NAME"] then ... end || In your case, it would be game.Teams.Hunters  ChristianTRPOC 64 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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

Player.Team
Ad

Answer this question