Value is not being found

Basically I have a billboard GUI and it will change the text to your intvalue, it was working fine a minute ago but now its saying the age is 0 when thats not true at all. I have no idea where its getting the 0 from either

Code:

local gui = game:GetService("ReplicatedStorage").GUIS.AgeB
game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		
		local clonedgui = gui:Clone()
		clonedgui.TextLabel.Text = "Age: "..player.Stats.Age.Value
		clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
		
	end)
	
end)

Is the script a local script? And if it is not a local script, are you changing it via client?

if you update the value via properties, a local script won’t see the changes, the default value is 0

Could it be that the Age IntValue hasn’t been loaded in by the time the script tries to find the value, meaning that it just takes the default value (0) before it is changed to 14?

Here’s a (likely) timeline:

  1. Player added.
  2. Stats added with empty values.
  3. Character added.
  4. Server checks Age IntValue, gets default 0.
  5. Age IntValue is updated to 14.

The script for the billboard gui is a serverscript and it shouldnt be changing via client, I have a remote that changes the value of your age.

remote code:

local ageEvent = game:GetService("ReplicatedStorage").Events.Age
ageEvent.OnServerEvent:Connect(function(player,age)
	player.Stats.Age.Value = age
end)

The age is saved through a datastore so I didn’t change the value via properties at all

That is possible. If so how would I fix this?

Couldn’t you just add the overhead GUI from the server whenever you load in the data rather than create and IntValue on the client? As in, put it in your data script. Example pseudocode:

local age = DataService:GetAge()
game.Players.PlayerAdded:Connect(function(player)
     player.CharacterAdded:Connect(function(character)
          createGui(character, age)
     end
end
1 Like