Player's UserId keeps returning as 0

So I have a script that puts a player’s user ID in a intvalue, but it keeps giving me 0.



print("start")
local function OnPlayerAdded(player) 
	while wait(0.5) do
	local cube = cubes[math.random(1, #cubes)]
	print(2)
	print(cube.occupied.Value)
	if not cube.occupied.Value then
		print(3)
			cube.owner.bill:WaitForChild("label").Text = player.Name
			cube.owner.bill.label:WaitForChild("User").Value = player.UserId
			repeat wait()
until player.UserId~=0
			print("success")
			cube.occupied.Value = true
			break
		else
		    print("retry")
	    end
	end
end



game.Players.PlayerAdded:Connect(OnPlayerAdded)

for i, v in pairs(game.Players:GetPlayers()) do 
	OnPlayerAdded(v)
end

What prints? What isn’t working? From what I can tell, the UserId is fine, and your logic is probably the issue.

It returns with a 0, and that’s the point I don’t see what’s wrong with this script.

Number value can store decimals and whole numbers. I’m not sure about this, try using IntValues.

Are you sure the code even reaches that point?

Are you testing this in a local server with Player1, Player2 etc or is this with your actual character?

Im testing with my ACTUAL character.

I don’t think that would change anything.

Have you tried to print the UserId or are you using the repeat statement as your indicator of it being 0?

It’s either that, or he can try waiting for the character to enter using the CharacterAdded event of Players.

Idk trial and error methods work :sweat_smile:

" A NumberValue is an object whose purpose is to store a single Lua number, defined to be double-precision floating point number,"

Yeah I don’t think the NumberValue is the issue.

Yes the script DOES print the userid and it prints a 0.

Is not cube.occupied.Value true?

1 Like

Oh that’s for something else.
The script is meant to pick a random area and I needed the UserID so I could let only the player who owned the area sit in a seat there.
Also that = false.

Can you provide the latest script.

Since that is false you are never actually setting the value of the NumberValue so it remains 0.

That still IS the latest script.

Does this same issue occur if you play it normally in game and not through studio?

1 Like

Maybe Enable HTTP and DataStores?

Maybe that’s why

Or u did not concatenate it with a string

Yes, I’ve tried playing ingame and the dev console stills shows the user id is 0.