Can't access LocalPlayer's UserId

UserId Not working?

-- Code is below.
print("h"..game.Players.LocalPlayer.UserId.."h")

	end
end)

Also here is output?

1 Like

ServerScripts can’t access to LocalPlayer because they are not running on a player’s device, they run on server.

You need a localscript to access the LocalPlayer.

You can only access the Local player on a local script.

Though on the server you can get the Player using the player added event:

Code:

--// Services 
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	print(Player.UserId) -- Outputs the player's id
end)
2 Likes