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

Why is this if statement triggering and how do I fix it?

Ok so I need the gui to only be activated if the players name is Plieax but when I play my game on another account the if statement still runs allowing the non-admin player admin abilities. How do I fix this?

game.Players.PlayerAdded:connect (function(plr)
	if plr.Name == "Plieax" or "" or "" then -- Put Names Of Admins Between The ""s -- 
		plr.PlayerGui:WaitForChild "OpenAdmin".Enabled = true
	end 
end)

1 comment

0

if I helped you out please accept my answer. Otherwise comment how I can help you better

2 answers

It would help if you used a table to save the admins names and used a function to check and see if they are a admin. Here is an example:

local adminList = {"Plieax", "Bob", "Joe"} -- names are examples

function checkIfPlayerIsAdmin(player) -- will equal false if the player is not an admin
	for i,v in pairs(adminList) do
		if v == player.Name then
			return true
		end
	end
	return false
end

game.Players.PlayerAdded:connect(function(player)
	if checkIfPlayerIsAdmin(player) then
		
		-- Put your code in here
	
	end
end)

3 comments

0

You messed up on line 7, just because the first name out of the table and the player don't match doesn't mean the 2nd name and the p^layer won't match!

0

remove the 'else return false' and on the end of the for i,v in pairs add return false, if it didn't return yet, it would return false, if it did, it would return true

0

You're right I messed up. This is a script I wrote a while back and I forgot the order it went in let me fix it.

game.Players.PlayerAdded:Connect(function(plr)
    if plr.Name == "Plieax" then
        plr.PlayerGui:WaitForChild "OpenAdmin".Enabled = true
    end 
end)

2 comments

0

you didnt change anything

0

he's actually right though, no one is ever going to have no name, this does exactly what you want it to do

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