Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make my lives gui update to the value of lives?

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

2 answers

✓ Accepted answer

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)

9 comments

0

I just get an error saying "Lives is not a valid member of Frame"

0

I tried it in the HUD gui and it didn't change anything, it didn't work. I dunno why I put it in the lives frame. Anyway, upon doing it in the hud it didn't have the value in the gui.

0

The error I got upon putting it in the HUD was "Players.shipleydog2.PlayerGui.HUD.LocalScript:6: attempt to index upvalue 'livesText' (a string value)"

0

oop that was typo on my part ill edit it

0

Alright.

0

It still doesn't work. I'm not getting any errors, either.

0

would you be okay with team creating and or talking over discord? would be easier to debug there

0

Sure, that's fine.

0

Lucy#0003

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.