✓ Accepted answer
When you use WaitForChild, there is no point in checking to see if it returns nil -- it won't return until it has a non-nil value.
To debug, use print statements to see if the script is even running and what it executes:
print("begin")
newPlayer = game.Players.LocalPlayer
print("player", newPlayer, "id:", newplayer.userId)
if newPlayer.userId == 32441993 or newPlayer.userId == 36491121 or newPlayer.userId == 37983438 then
print("user is admin")
a = game.Lighting:WaitForChild("Admin")
print("game.Lighting.Admin returned", a)
backpack = newPlayer:WaitForChild("Backpack")
print("backpack:", backpack)
a:Clone()
a.Parent = backpack
print("gave admin to player")
end
end
end
print("done")
One error I see is that you call "a:Clone()" but then you don't use the clone. This error wouldn't cause a syntax error, it'd just move the Admin from the lighting to the newest player, meaning that the script would appear to work the first time, but not the 2nd. You could do a:Clone().Parent = backpack instead.
1 comment
You could check the player's name instead of the userId, and use a playeradded event.