I’m trying to make a text button that can only be seen by certain players.
Can anyone help me with this?
Thanks.
Insert a Client-side script in your text button, and type this
for i, v in pairs(game.Players:GetPlayers()) do
if v.Name == "helloiamservent" or v.Name == "Someone" then
script.Parent.Visible = true
else
script.Parent.Visible = false
end
end
– We’re getting a table of all the players,
– We’re checking if the player’s name, is what I wrote here.
– If so make it visible!
(Change Someone and helloiamservent to your name or whoever you want)
– Local Script in StarterGui
for i,v in pairs(game.Players:GetChildren()) do
if v.Name == "Player" or v.Name == "Troll22" then
script.Parent.Visible = true
else
script.Parent.Visible = false
end
end
Not much else to add tbh
if you wants put a lot of players o some players u can do this
local certainPlayers = {"person1", "person2", "person3"}
local plr = game.Players.LocalPlayer
for i = 1, #certainPlayers do
if certainPlayers[i] == plr.Name then
button.Visible = true
end
end
in startergui- local script or a local script inside the button
This script would have to be parented to the TextButton you want to hide/show.
This guy probably knows that, Because it wouldn’t make sense for it to be parented to the Workspace or something. Lol
The response you posted said to parent it to StarterGui so I was helping to clarify
I meant the button to be in Starter Gui, but if you change the location of the text button then just change the location in the code, or create a variable.
You can make a table, and do a for loop to loop through the player IDs or names, and if they match, you can leave it, if not, go ahead and delete the gui.
That would be a more efficient way.
You could use that for a story game. To check if every Player is there for dialogue or something.
You should probably destroy the GUI if the player is not whitelisted. This prevents exploiters from viewing private information as they may be able to run some client-sided code, including making GUI visible to them.
Hope this helps you. If you need any further help do contact me here on the DevForum or on Discord, solo.#0001
Thanks for helping me! Really useful
I think hackers can access the UI before the script could do anything.
for i, v in pairs(game.Players:GetPlayers()) do
if v.Name == "FlatRight" or v.Name == "FlatRight" then
script.Parent.Visible = true
else
script.Parent.Visible = false
end
end
I don’t know what that red thing is.
It’s because you have already mentioned “FlatRight” here.
Put someone else here
you should compare the user id instead
or convert those names to string and lower it with also the compared string