Attempt to index nil with 'UserId'

  1. What do you want to achieve? Keep it simple and clear!
    I want to make an admin Gui visible to only me.

  2. What is the issue? Include screenshots / videos if possible
    Serverscritpt:

local starterGui = game:GetService("StarterGui");
local screenGui = starterGui:FindFirstChild("ScreenGui");
local img = screenGui.ImageLabel;

local players = game:GetService("Players");
local player = players.LocalPlayer;

local UserId = player.UserId;

if UserId == 120640653 then
    screenGui.Enabled = true;
end;

How do I do this?

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Because this is a regular script, you cannot get the LocalPlayer, you have to use a localscript instead to get the LocalPlayer property of the Players service

1 Like

but isn’t it unsafe to do this on local scripts?
i heard exploiters can access them

If you’re worried about that, then you can use PlayerAdded instead to see if the UserId of the player who just joined is equal to the specified id and just enable the gui from their playergui

players.PlayerAdded:Connect(function(player)
	If player.UserId == 120640653  then
		local guis = player:WaitForChild("PlayerGui")
		guis.ScreenGui.ImageLabel.Enabled = true
	end
end)
2 Likes

instead of getting the player from LocalPlayer make a PlayerAdded event and check if the player is you

You should create a table called

 Admins = {"name", "Name", "etc"}
for _, admin pairs(Admins) do
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
         if admin == player.Name then
                 -- Enable UI
        end
    end
end

You could do something like this

1 Like

ok thanks for the help, but what do i do if this delays?

It wouldn’t delay. PlayerAdded occurs when a player first joins and if theirs any delay then its the clients ping spiking heavily.

1 Like

I don’t believe the event will delay since it runs whenever a player joins your game, the only thing that you need to do is wait for their PlayerGui to load before doing anything

1 Like

Don’t worry too much. If the Admin Gui doesn’t appear on your screen it might be a bug. Just add a wait() at the start of the script.

Edit: It sometimes also occur if you’re not loaded

1 Like

Replying late, you put colon instead of dot

1 Like

Make a script in ServerScriptService, called it Admin or anything you want.

In the script decide whether you want it to be based of the Players Name or Players Id

Create a Table

AdminTable = {"IfYouChooseName",234234234234,23423423424} -- Do Name or Id

Then you when a player connects you want to check whether they have admin

game:GetService("Players").PlayerAdded:Connect(function(Player)
   for _, admin in pairs(AdminTable) do -- Loops through the admin table
      if admin == Player.Name or admin == Player.UserId then
            player.PlayerGui.NameOfScreenGui.Enabled = true -- Enable the frame
      end
   end
end)

I hope this helps, if you have any issues then let me know.

Woops, I guess I must’e typed a bit too fast haha, I edited it to fix that, thanks!

@Interactivated If you get an error about a : where it shouldn’t be, try the code now as I edited to fix what @AridFights1 Noticed

1 Like

I think you made a mistake on line 4 with “player” because you passed “player” with a capital P in the function

I don’t think it matters what you pass through it as long as you know its a player.

ok so when i used ur script i got this:

ScreenGui is not a valid member of PlayerGui "Players.Interactivated.PlayerGui"

here the script btw

local adminTable = 
{
        120640653,
        1
    }

game:GetService("Players").PlayerAdded:Connect(function(Player)
    for _, admin in pairs(adminTable) do
        if admin == Player.UserId then
            Player.PlayerGui.ScreenGui.Enabled = true;
        end;
    end;
end);

Is the you ScreenGui called “ScreenGui”?

Yeah, its just called a ScreenGui

https://i.gyazo.com/646cc74b8d64c04a2f9a975ed56dd8e7.png