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

Comparing strings not working with if statement?

I'm trying to set up a system to check to see if the user is an admin and if they are they are given the admin panel that I have made.

Here's the code Ps its in the ServerScriptService if that matters at all

-- Give Admin Panel function
local Admins = {"Bosskiller177", "Test 2"}
local function checkPlayerForAdmin(plr)
	
	local adminPanel = game:GetService("StarterGui")["Admin Panel"] -- Gets the Admin Panel
	for index = 1, #Admins do
		
		if Admins[index] == plr then
			print("Admin")
			adminPanel.Enabled = true
			break
		else
			print("Not Admin")
			adminPanel.Enabled = false
		end
		
	end
end


game.Players.PlayerAdded:Connect(function(plr)
	checkPlayerForAdmin(plr)
end)

I've looked all over but the results are either to complex for me or just doesn't work Why is lua being like this, any other language ive learnt makes this process so easy, but not with lua

1 answer

The problem with this code is that you're trying to compare a Player object with a string.

if Admins[index] == plr then

plr isn't a string or the name of the player that joined, but rather the Player object itself. To fix this problem, you can compare the string with the Name property of the player, aka. the username.

if Admins[index] == plr.Name then

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