✓ Accepted answer
You'd use tables!
A table is a data type in Lua that is useful to store multiple values. Each value in the table is separated by a comma and is indexed 1 through the number of items in the table.
local users = {123432, 525322, 32523523}
We can use a For loop to iterate through each item in that table and see if any value in the table matches with the player who joined's UserId.
The for loop will run i times (i = amount of items in the table)
local function checkIfUserIsAdmin(userId)
for i, v in pairs(users) do
if userId == v then
return true
else
return false
end
end
end
To help you understand for loops more:
local users = {123, 312, 542}
for i, v in pairs(users) do
print(i, v)
end
The expected output would be the following(Note that the loop ran three times where i= the number of times the loop ran and v = the value):
1 123
2 312
3 542
As such, your code can be re-written as:
local users = {123432, 525322, 32523523}
local tool = game.ServerStorage.GreenBalloon
local function checkIfUserIsAdmin(userId)
for i, v in pairs(users) do
if userId == v then
return true
else
return false
end
end
end
function onPlayerSpawned(player)
if checkIfUserIsAdmin(player.UserId) then
tool:Clone().Parent = player.Backpack
else
print("User does not have permission")
end
end
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function()
onPlayerSpawned(player)
end)
end)
2 comments
I belive you should use a table.
you could just put the balloon in starterpack