Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a GUI only display to certain people?

I have a speed button in my game, but I only want it to be only for specific people. My issue right now is that the button displays to everyone. Here's my code right now.

game.Players.PlayerAdded:Connect(function(plr)
	game.StarterGui.ScreenGui:WaitForChild("Button")
	if plr.UserId == 123 or plr.UserId == 321 then
		script.Parent.Visible = true
		script.Parent.Active = true
	else
		script.Parent.Visible = false
		script.Parent.Active = false
	end
end)

I have this script in the button I want to display, and it is a local script.

(Btw I'm inexperienced in Lua, I just started recently)

2 answers

✓ Accepted answer

The easiest way to accomplish this would be to insert the following code inside a LocalScript, which should be inside the button.

You shouid also set Visible = false manually by changing this in properties

local list = {35910290, 12421, 41221} --Here, we create a table which stores the UserIds of all users who you want the GUI to be visible for. It's much better to use UserId's over usernames since you can change usernames on ROBLOX!

local button = script.Parent --Here we create a variable "button", which refers to the script.Parent(which is the button you want to be visible). This can be a frame too.
local player = game.Players.LocalPlayer --Creating a player variable which refers to the LocalPlayer

for _, userId in pairs(list) do --Here we create a forloop where we will iterate through each item stored in the "list" table(UserIds) We will compare each userId with each value in the table to see if they match (This would mean that we need to make it visible for them).
	if (userId == player.UserId) then --If they are on the list, then
		button.Visible = true --Make the button visible
	end
end 


Cleaner version, without all the comments:

local list = {35910290, 12421, 41221} --userIDS

local button = script.Parent
local player = game.Players.LocalPlayer

for i, userId in pairs(list) do
	if (userId == player.UserId) then
		button.Visible = true
	end
end 


5 comments

0

Huh. This doesn't work either.

0

Yes it does. I tested it myself. Did you put it in a LocalScript, inside the GUI you want to be visible? Did you set the button to not visible in the property panel? You also need to make sure to add your userID in that table! Your userId = 171801589

0

If you still can't get it to work, send me a picture of your Explorer so I can try and assist you further.

0

OH I have the GUI set to visible by default. Let me test that.

0

Yep this works great! Thanks so much!

I've been using the or function, and it doesn't work for me, so I used a list instead. ALSO: Your using the startergui, which is not located in the player. To do so, use playergui, as in the script.

local list = {"165", "132"} --User id's of wanted players
game.Players.PlayerAdded:Connect(function(plr)
	local passed = false
    plr.PlayerGui.ScreenGui:WaitForChild("Button") -- not practicall but okay,
	for i,v in pairs(list) do -- Loops through the list of Userids
   	 if plr.UserId == v then --  Checks if the player's UserId is equal to one in the list
      	  passed = true -- If so, they passed
   	 end
	end
	if passed == true then -- if they pass, they get the gui, if not, rip.
		script.Parent.Visible = true
     		script.Parent.Active = true -- not needed
   	else
       		script.Parent.Visible = false
     		script.Parent.Active = false -- Not needed
	end
end)

3 comments

0

Ok. But where would I move the button to? I don't see a tab for PlayerGUI.

0

This won't work assuming this script is in a GUI because the player would have already joined the game by the time the script loads. You're also comparing a userId(which is an int) with a string

0

JoshGamingHQ1, Everything in StarterGui gets replicated into PlayerGui(which is located inside the player) upon spawning.

This discussion is preserved as it was. New answers, comments, and votes are closed.