Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Comparing userId's help?

Asked by
NotSoNorm 777 Moderation Voter
9 years ago

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

Log in to vote
1
Answered by 9 years ago

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)
0
well boy, Don't I feel dumb NotSoNorm 777 — 9y
0
yes YellowoTide 1992 — 9y
Ad
Log in to vote
0
Answered by
unmiss 337 Moderation Voter
9 years ago

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)

Answer this question