I am trying to make a script that prints the value of a number in a textbox, but it’s not working. I want to make a surfacegui swap whenever a person has hit a certain number of rebirths. I am trying to get the value but I don’t think I’m either getting the player and/or their leaderstats properly. Can anyone please let me know what I’m doing wrong.
local ms = script.Parent.Carscreen
local as = script.Parent.Altscreen
local Rebirths = game.StarterGui.RebirthGui.RebirthsFrame.TextLabel
game.Players.PlayerAdded:Connect(function(player)
if player.leaderstats.Rebirths.Value > 1 then --should detect whether the value equals a certain value needed
as.Enabled = false
ms.Enabled = true
else
as.Enabled = true
ms.Enabled = false
end
Here’s where the value can be found in the leaderstats:
You’re probably running into race-condition problem.
Server PlayerAdded creates values and replicates them into client
Server calls datastore asynchronously to populate these values
Client PlayerAdded runs and sees that player.leaderstats.Rebirths.Value is 0
Server obtains the data from datastore and so values are populated
This means that client has checked for the values but server wasn’t fast enough to get the data from datastore and set these values.
Best option to validate is to use print and print these values into console, and check who was faster.
Other possible issue could be that client’s PlayerAdded event wasn’t even invoked, because this won’t catch local player connection.
Important to mention is that everytime new player joins the game, this could change your GUI, because you’re checking for Rebirths of every new player.
You join the game, have 0 rebirths, got default UI
John has joined the game, has 2 rebirths, and “for some reason”, Your UI is not default anymore
Best solution would be sending RemoteEvent to the particul client that their data are ready.