Gui text doesnt update on player death

hello, I am trying to set up a system so that in the players gui it shows the players money , and to chang the money I used .changed to update the text, the only problem is when the player joins or dies the text resets back to it’s default value. I have tried using player.CharacterAdded to also connect to the function but this doesn’t work and I’m simply confused on how this work

Can you please show your script in order for us to help you more quicker?

local function moneyChangeText()
	visibleMoneyBalance.Text = player.leaderstats.Money.Value
end

player.leaderstats.Money.Changed:Connect(moneyChangeText)
player.CharacterAdded:Connect(moneyChangeText)

There should be a property in the ScreenGui you are using called “ResetOnCharacterAdded” or something along those lines. Set that to false and you should be good to go.

I believe the issue is that your ScreenGui is set to reset when a player respawns. Uncheck the ResetOnSpawn property in the properties section of the ScreenGui.

Edit: Also, you probably want to remove the CharacterAdded function for updating text, as there is no use of it if your issue has been fixed. You should also have the text to update first when the script runs.

Here is your fixed script:

local function moneyChangeText()
	visibleMoneyBalance.Text = player.leaderstats.Money.Value
end

moneyChangeText()
player.leaderstats.Money.Changed:Connect(moneyChangeText)
1 Like

ok well doing that helped when I reset, but now when I first join the game it still doesn’t show the money. My question is why does characteradded not fire the function, or should i be using something else to detect this. I believe, because i tried other methods, because the playergui hasn’t loaded in before it’s fired that something breaks

I have edited my previous post above, try using that script and see if it works.

Also to answer your question,

I believe CharacterAdded does not fire in a local script when it’s under PlayerGui (or probably under a ScreenGui). Try the code I have given in my edited post above.

teamChangeText()
player.Changed:Connect(teamChangeText)

ok so I have the same thing right here, but I am consistently getting this error message

mainMenuButtons is not a valid member of ScreenGui “openingMenu”
as well as
Infinite yield possible on ‘openingMenu:WaitForChild(“mainMenuButtons”)’
both make absolutely no sense to me,

Could you possibly show your full script?
Also, the code you have just provided

it appears you are trying to check if some player property has changed.
Change that line of code to this:

player.leaderstats.Money.Changed:Connect(moneyChangeText)

ok so basically I had it set up so that when I turned off reset on spawn it actually broke it, so i reactivated it and just changed a few things and it seems to be working well enough for now. your suggestions helped me a lot though and i appreciate it

1 Like

Alright, I’m glad it works now. Happy to help!

1 Like