Local player's UserId starts at zero and changes in Test Sever + Players

In Roblox Studio, the local player’s UserId starts at 0 before changing to the correct value in runtime.

This bug was experienced in Roblox Studio Version 0.365.1.265265 running on macOS Mojave 10.14.1.

Repro steps

This can be seen with the following code placed into a LocalScript in StarterPlayerScripts

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

print("LocalPlayer UserId is ", LocalPlayer.UserId)

LocalPlayer:GetPropertyChangedSignal("UserId"):connect(function()
    
    print("LocalPlayer UserId now ", LocalPlayer.UserId)
end)

When run in Test Solo the output is (correctly) as follows:

LocalPlayer UserId is 123456

When run in Test Server + Player, the output is (incorrectly) as follows:

LocalPlayer UserId is 0
LocalPlayer UserId is now -1

Expected Behaviour
LocalPlayer.UserId at the top of a LocalScript in Test Server + Player returns the correct UserId (ie -N)

Actual Behaviour
LocalPlayer.UserId at the top of a LocalScript in Test Server + Player returns 0 before changing to the correct UserId after an arbitrary amount of time (0.0067 seconds in my test)

9 Likes

+1
This is still an issue for me in my projects.

2 Likes

This caused me a lot of trouble today.

had this happen to me too. gets annoying when you’re trying to test projects in studio

Couldn’t you just do a simple repeat wait loop?

repeat wait()
until game.Players.LocalPlayer.UserId~=0

1 Like

The point of this thread is to address the issue so that developers do not have to use workarounds for something that isn’t behaving as expected.

I know, I wasn’t saying that there shouldn’t be a fix.