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

i get player is not admin even thoug i am?

Asked by 2 years ago

i am trying to make a script for to check if a person is or is not admin

local player = script.Parent.Parent.Parent.Name
local players_allowed = {jeremqpmfpi}

wait(1)
for i, v in pairs{players_allowed} do
    if player ~= players_allowed[1] then
        print("player is not admin")
    else
        print("player is admin")
    end
end

note: it is in the player gui and i am jeremqpmfpi

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Arrays start counting from 0, so your username in the array is at position 0. For example, [A, B, C, D], A would be index 0, B index 1, C index 2 etc.

When you call players_allowed[1] you're calling the index after your username, which is undefined.

You could look up how to integrate over an array to make your code a bit cleaner :)

This isn't the best method but it's an ok example...

for index, player in ipairs(players_allowed) do //notice not curly brackets, also notice "ipairs" is used for arrays where as "pairs" is used for dictionaries (i stands for indexed)
if player == player_allowed[i] then//this will compare the username to every value in the list
print(player ... " Is an admin")
end
end

Apologies if I've missed something I haven't done pus in a while and I'm on mobile lol

Ad

Answer this question