Help with getting player.UserId then (if statement)

Hello!

During my game developpement, I wanted to thank some special people, as of now I am trying to first: See their Id AKA identify them.

This is my first time trying something like this, so I might do a dumb error.

When trying the script (its parent is ServerScriptService), the error that came from the OutPut was this:

ServerScriptService.SpecialPeople:3: attempt to index nil with 'UserId' 
local Player = game.Players.LocalPlayer
wait(1)
if Player.UserId == 74963446 or Player.UserId == 484327688 then 
	--The first Id is the person I'm trying to give something and the second Id is mine just to test
	print("The Special Person joined!")
end

So I might be doing an error I might not be seeing, but please tell me and maybe link a DevHub Article.

Thanks for reading!

The Local Player can only be used on the client in Local Scripts, as Local Scripts only run for the one person. The server, however, looks after all players, meaning there’s no such thing as a localPlayer, since it handles ALL the players.

To fix this, you could use a PlayerAdded Event.

Edit: Here’s a helpful article about the Player Added Event: Players | Roblox Creator Documentation

2 Likes

^^^^^^^^^^

Benified4Life is correct.

game.Players.PlayerAdded:Connect(function(plr)
if(plr.UserId == 74963446 or plr.UserId == 484327688) then
print(“special”)
end
end)

Example code

2 Likes