So here's something important to note: LocalScripts do not run until after the player instance is created. (Which makes sense given that for something to run on the client, there needs to be one)
This means that when we have our PlayerAdded listener in a local script, it won't have started listening in time to pick up on our client being created. So how do we get around this? Well, luckily for us, the LocalPlayer property of the Players service exists.
LocalPlayer points to the player instance of the client running the local script. It's important that we do this for another reason too; the PlayerAdded function will not only not fire when our player joins (for the aforementioned reason) but it will when other players join, which isn't the behavior you seem to want.
So, now that we know that if we want to get the player currently running, the local-player, we simply need to access the LocalPlayer property of Players. Hence our script should look like this:
E: We're also going to remove the characteradded listener, since changes made to the coregui persist until manually reverted regardless of the character being respawned.
local sg = game:GetService("StarterGui")
local te = game:GetService("Teams")
local plr = game:GetService("Players").Player
if plr.Team == te.Solitary or plr.Team == te["Class - D"] or plr.Team == te["Chaos Insurgency"] then
plr:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
end
Hope this helps.
5 comments
dont use the player added event on the local script, local scripts are put into the player/character when the player joins or the character is created
you can also just use player.Character
is plr.Team a string or an object, I can't remember because I hardly use them; but if it's a string, you are comparing team objects to a team name string. This may be the issue. Try te.team.Name.
But also, as theking said - don't use PlayerAdded for LocalScript here, you should only need to access LocalPlayer.
SCPPPPPPPPPPPPPPPPPPp