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

How would I make a button non-visible to any non eligible characters?

I am making a team change GUI and me and my friend want it so that only me and him can see a specific button to join a specific team while allowing everyone to see the other buttons for other teams, I know how to make it change the players team, I just need to know how to make it is so that if the players name is equal to the "eligible" players list name, then a button will be visible.

Here's an example code of what I mean:

local EligiblePlayers = {"thesavagery212", "Sinx_Clair"}
local plr = script.Parent.Parent.Parent.Parent.Parent.Name

if plr == EligiblePlayers then 
	script.Parent.Visible = false else
	script.Parent.Visible = true
end

Sorry I am not the best coder.

1 comment

0

This should fix it for you.

local EligiblePlayers = {"name", "Sinx_Clair"}
local plr = game.Players.LocalPlayer.Name

for i,v in pairs(EligiblePlayers) do
	if not plr.Name == v then
		script.Parent:Destroy() -- Destroying is more secure than turning off visibility.
	else
		script.Parent.Visible = true
	end
end


1 answer

✓ Accepted answer

1 error I can see in your code is; you didn't reference the local player, as the client only needs to see this, and not the server.

It's also more convenient to use a loop whilst checking usernames.

Here's an example of a working code to precede:


local plr = game.Players.LocalPlayer
if plr.Name == "" then --your name

-- Also, if you want to add more names you can either use a , after the name or add more if statements!
script.Parent.Visible =  true
else
script.Parent:Distroy()
end

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