So I have a script basically for a somewhat a whitelist system; if your user id is found in it then it sets a variable (local val = true) and if not found then kicks you.
The thing is when I do this;
for i, v in pairs(whitelisteduserids) do
if v == userid then
val = true
print("authorized")
break
elseif v ~= userid then
val = false
player:Kick()
break
end
end
The issue is like, no matter what even if the User ID is indeed in the whitelist table it will still kick them, so how do I prevent it? Is it breaking the loop that’s the problem or what ?
Most likely the issue is that you shouldn’t kick the player immediately when v ~= userid, because it might not be the first one on the list. Try kicking them after you check all the UserIds. Here’s an example of what I mean.
for i, v in pairs(whitelisteduserids) do
if v == userid then
val = true
print("authorized")
break
elseif v ~= userid then
val = false
end
end
if val == false then
print("unauthorized")
player:Kick()
end
Just use what @J_Angry said but maybe he forgot to add 1 thing to the script, anyway here’s it:
for i, v in pairs(whitelisteduserids) do
if v == userid then
val = true
print("authorized")
break
elseif v ~= userid then
val = false
break
end
end
if val == false then
print("unauthorized")
player:Kick()
end