How can I make this script work?

Hello, I was wondering how I could make this script work, because the admin GUI is still visible to everyone else, so here is my code.

if game.Players.LocalPlayer.Name == "BrokenGri","MyBigFreak","Wy588" then
 script.Parent.Enabled = true
else
 script.Parent.Enabled = false
end
2 Likes

Personally I would use PlayerGui. PlayerGui is local and only is visible to the client.

(Tip use UserId instead of the Player Name)

if game.Players.LocalPlayer.Name == "BrokenGri","MyBigFreak","Wy588" then
 player.PlayerGui.GuiNameHere.Enabled = true
else
 player.PlayerGui.GuiNameHere.Enabled = false
end
1 Like

If this was done for the conditional statement to return true for multiple player names, then it won’t work for the purpose - try using tables instead

local player = game.Players.LocalPlayer
if table.find({"player1", "player2"}, player.Name) then
    --// stuff
end

I’m assuming this is a LocalScript, make checks like these on the server unless you want people to be able to bypass them.

2 Likes

I suggest you put the gui under serverstorage and when player joins, make a server script to check if it’s the good name. If it is, clone the gui and put it in the player gui since if it’s in StarterGui, exploiters could easy enable/disable it.

2 Likes

Yes it is a LocalScript and I will be sure to make checks on the server because that is important.

if game.Players.LocalPlayer.Name == "BrokenGri" or "MyBigFreak" or "Wy588" then
   script.Parent.Enabled = true
else
   script.Parent.Enabled = false
end

I have already tried that , sadly but that did not work.

Try this and remember to put it in ServerScriptService:


local GUI = game.StarterGui -- Gui

game.Players.PlayerAdded:Connect(function(player)
     player.CharacterAdded:Connect(function(character)
        if player.Name == "BrokenGri" or "MyBigFreak" or "Wy588" then
         GUI.Enabled = true
     else
         GUI.Enabled = false
      end
   end)
end)
1 Like

Here :

Create a Script in “ServerScriptService”,

Put the player added function like that :

game.Players.PlayerAdded:Connect(function(player)
    local Gui = player.PlayerGui.GuiNameHere
    if player.UserId == theUserIdOfBrokenGri, theUserIdOfMyBigFreak, theUserIdOfWy588 then
        Gui.Enabled = true
    else
        Gui.Enabled = false
    end
end)

Try using userId more often because player names can easily change but not the userId.
Edit : Forgot an “end”.

1 Like

This won’t work how you think by the way, due to how that keyword works if the player’s name isn’t the first value (“BrokenGri”) then the code in that block will always run since strings (and anything other than false and nil) are truthy values, to do what you probably meant:

local name = player.Name
if name == "BrokenGri" or name == "MyBigFreak" or name == "Wy588" then

end

not how it works

local var = 1
local cond = var == 2, 1, 3 -->> false, because it'll only compare against the first value (the one before any commas)

even using or with the commas won’t work as expected.

Was excepting him to put the “or”

That’s why if u have a admin GUI Before u execute the command whatever u do another for i,v in pairs loop looping through the table to see if the name is good or not.

Won’t that clone it into everybody’s player gui? if BrokenGri joins the game.