Money Gui don't work in game

Hello, I made a money Gui (with tutorial) and it work when I test it on studio (see the screenshot). But after publishing in the real game, the money Gui don’t work anymore (see the second screenshot). Someone can help me to fix it please ?
Screenshot of studio in test :


Screenshot in real game :
The script (local script in textlabel):
Thanks

1 Like
local Stats = game.Players.LocalPlayer.leaderstats:WaitForChild("Cash")

Stats:GetPropertyChangedSignal("Value"):Connect(function()
      script.Parent.Text = "Cash: "..Stats. Value
end)

Avoid FindFirstChild

Because it may load even before the player is added

I tryed with your script but still don’t work (still do same thing).

Sorry about that

while wait() do
        local Stats = game.Players.LocalPlayer.leaderstats:WaitForChild("Cash")

        script.Parent.Text = "Cash: "..Stats. Value
        wait(0.05)
end
3 Likes

Thanks, it work now, thank you so much two hours I m working on it :smiley:

This may work

while wait() do
local Stats = game.Players.LocalPlayer:WaitForChild(“leaderstats”):WaitForChild(“Cash”)
script.Parent.Text = "Cash: "…Stats.Value
end

It is not necessary to use :GetPropertyChangedSignal for value objects, it only fires when the Value changes

Also using wait() is a bad habit for cases like these, try using the .Changed event instead.

  ValueObject.Changed:Connect(function(newValue)
        TextLabel.Text = newValue
  end)

@Kyo_Online

@FerbZides’s solution will work, but the appropriate and efficient way to do this is to utilize the Changed event to avoid constantly looping unnecessarily.

Someone send me something similar who work too, thank anyway for helping :slight_smile:

I did not do this before

local Stats = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")

Stats:GetPropertyChangedSignal("Value"):Connect(function()
      script.Parent.Text = "Cash: "..Stats. Value
end)

This is efficient because it waits for the leadership and everything instead of just getting them all instantly

Ok, thank you for helping (Im very bad in script :sweat_smile:) Thanks

Still have issues what code u tried now?

The one I put in solution, work for me actually

it is still unnecessary, the .Changed event only fires when the value changes anyways.

@Kyo_Online Here is a better alternative, efficient compared to using a while wait() loop


  local players = game:GetService("Players")
  local player = players.LocalPlayer
 
  local leaderstats = player:WaitForChild("leaderstats") 
  local cash = leaderstats:FindFirstChild("Cash")


  cash.Changed:Connect(function(newVal)
       script.Parent.Text = "Cash: ".. newVal
  end)

Also try using :GetService() instead of using dot syntax for services.

edit: @FerbZides Then you probably did it wrong, try this

If the name of the value changes the script Breaks

That’s why I don’t use. Changed