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)
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
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)