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

Help with looping player names?

Asked by 8 years ago
local admins = {"NinjoOnline", "MerchantVIII"}

local player = game.Players.LocalPlayer

local hud = script.Parent

local adminButton = hud:WaitForChild("AdminButton")

print("Variables Checked")

game.Players.PlayerAdded:connect(function(player)
    print("1")
    for _, v in pairs(admins) do
        if player.Name == v then
            print(v.Name)
            adminButton.Visible = true
        end
    end
end)

This is in a LocalScript. It doesn't print("1"). Before anyone says 'PlayerAdded doesn't work in LocalScripts', if you have seen the ROBLOX Wiki, it stats at pretty much the top that this function now works inside the client. It prints ("Variables Checked"), so the error seems to be when the player is added. Please help.

1 answer

Log in to vote
1
Answered by 8 years ago

Bad practice

You shouldn't be using PlayerAdded in a LocalScript.

But the Wiki says it works
The Wiki doesn't say you should use it, and you certainly shouldn't be checking other people's stuff from a LocalScript. There's a reason that you can't see other Player's PlayerGuis from a LocalScript.

So what do I do?
Ditch the PlayerAdded - You don't need it. Your LocalPlayer is already the Player who just joined the game, and the only one you need to worry about. Congratulations, you just saved yourself some lines and some issues.

Ad

Answer this question