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

Why doesn't my script remove the leaderboard?

Asked by
Jexpler 63
5 years ago

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.

1
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 theking48989987 2147 — 5y
0
you can also just use player.Character theking48989987 2147 — 5y
0
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. SummerEquinox 643 — 5y
0
But also, as theking said - don't use PlayerAdded for LocalScript here, you should only need to access LocalPlayer. SummerEquinox 643 — 5y
0
SCPPPPPPPPPPPPPPPPPPp greatneil80 2647 — 5y

1 answer

Log in to vote
0
Answered by
systack 123
5 years ago
Edited 5 years ago

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.

0
Found an error. "local plr = game:GetService("Players").Player" should say "local plr = game:GetService("Players").LocalPlayer". MatthewCenance 35 — 5y
0
Also, "plr:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)" needs to be replaced with "game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)" as that method exists in the StarterGui object, not the Player object. MatthewCenance 35 — 5y
Ad

Answer this question