I'm working on a game that uses a lives system. The lives and resetting you to the begging part works fine, but I have a gui I want to display the number of lives you have left. It currently doesn't change upon death and always shows the value of the text as it is before playing, which is "Value". Is there some kind of way to update it upon the value changing?
Screen snip:
https://imgur.com/a/nJc4DHH
How you're currently doing it wont work because you're changing the gui in the startergui instead of the player gui.
When the player joins, anything inside of the StarterGui gets copied into the player's player PlayerGui (game.Players.LocalPlayer.PlayerGui)
To update the gui whenever the value changes, you can use a value object's .Changed. .Changed runs whenever the value object (in this case, Lives
)'s value gets changed.
Directly inside the HUD gui, have a localscript containing the following:
local livesValue = game.Players.LocalPlayer:WaitForChild("Lives") --here i'm making the I'm the assumption that the lives value object is inside the player. let me know if it's not local livesText = script.Parent.Lives.LivesValue livesValue.Changed:Connect(function(newValue) livesText.Text = tostring(newValue) end)
This is not so hard, you need to use the "Changed" event, here's an example script for you.
local LifeCount = game.Players.LocalPlayer.WaitForChild("Lives") local LifeCountText = --Refer to the Text here LifeCount.Changed:Connect(function() LifeCountText.Text = "Lives: " .. LifeCount.Value -- Whenever the LifeCount changes, the text will be updated end)