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

The GUI destroys itself even when your name is in the value, what do I do?

I have no idea what i'm doing wrong but I am trying to make it so it doesn't destroy the gui if your name is in the admins table. How do I do this? Please use answers so I can reward you if your comment helped!

-----------Variables-----------
admins = {"MillerrIAm",""}
name = game.Players.LocalPlayer.Name
-----------Main Code-----------
if name == admins then
	wait()
else 
	script.Parent:Destroy()
end

Thank you in advance!

2 answers

✓ Accepted answer

Admins is a table, so your if statement will be always false. Use dictionary instead:

-----------Variables-----------
admins = {
	["MillerrIAm"] = true,
	["Sleazel"] = true, --just joking, remove that line :) But that is how you add more admins
	}
name = game.Players.LocalPlayer.Name
-----------Main Code-----------
if admins[name] then
    wait()
else 
    script.Parent:Destroy()
end

BTW, make sure you check for admin privileges on server as well, otherwise it is a disaster waiting to happen.

2 comments

0

How would I do that?

0

I have a question for you, is there a way I can se this to make it into a server script where it cant be effected by exploiters?

You need to loop through the table to check if any of the values match your players name, shown below.

admins = {"metalive"}
player = game.Players.LocalPlayer
function checkWhitelist(playerName)
	local whitelisted = false
	for i,name in pairs(admins)do
		if playerName == name then
			whitelisted = true
		end
	end
	return whitelisted
end

if checkWhitelist(player.Name) then
	print("Whitelisted")
else
	print("Player is not whitelisted")
end

If you want to remove the GUI before it's loaded for the player then it needs to be in a server script. If you want to remove the GUI when the player joins then:

admins = {"metalive"}

function checkWhitelist(playerName)
	local whitelisted = false
	for i,name in pairs(admins)do
		if playerName == name then
			whitelisted = true
		end
	end
	return whitelisted
end

game.Players.PlayerAdded:Connect(function(player)
	if checkWhitelist(player.Name) then
		print("Whitelisted")
	else
		local Ss, err = pcall(function()
			local playerGui = player:WaitForChild("PlayerGui")
			local gui = playerGui:WaitForChild("gui")
			gui:Destroy()
		end)
		if Ss then
			print("Gui removed")
		else
			warn(err)
		end
	end
end)

3 comments

0

your script did not work, i tried everything you said. it didn't work.

0

Working perfectly for me so you're doing something wrong on your end.

0

my guy, i did everything exactly as you said.. there's not much I can do for your stuff.

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