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

Comparing userId's help?

I've got this script to compare userId's to check if a player is on a list. but everything prints and two of the prints match but they don't print the "You're an admin " part. Why?

local admins = {"4376147","30701890"}

script.Parent.PAE.OnServerEvent:connect(function(player,player1)
	for i,v in pairs (admins) do
		print(player1.userId)
		print(v)
		if v == player1.userId then
			print("You're an admin "..player1.Name)
		end
	end
end)

2 answers

✓ Accepted answer

You're comparing their userid (number) to a string.

Two ways to fix this:

Call tonumber() on v. Or make the values in admins numbers

local admins = {4376147, 30701890} --these are now numbers not strings

script.Parent.PAE.OnServerEvent:connect(function(player,player1)
    for i,v in pairs (admins) do
        print(player1.userId)
        print(v)
        if v == player1.userId then
            print("You're an admin "..player1.Name)
        end
    end
end)

2 comments

0

well boy, Don't I feel dumb

0

yes

An easier way to accomplish such a method

local admins = {4376147, 30701890}

script.Parent.PAE.OnServerEvent:connect(function(player,player1)
	if admins[player1.userId] then
		--[[ code ]]
	end
end)

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