I want to remove to leaderboard for certain teams. So I have this:
local sg = game:GetService("StarterGui") local te = game:GetService("Teams") game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) if plr.Team == te.Solitary or plr.Team == te["Class - D"] or plr.Team == te["Chaos Insurgency"] then sg:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false) end end) end)
It doesn't work. It's a local script. It's in StarterPlayerScripts Filtering Enabled is on.
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.