Changing text via script not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A bar that goes down every second, and every second the text changes to display the number value of whats left of it.
  2. What is the issue? Include screenshots / videos if possible!
    The text will not change
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Everything bro
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local MaxStamina = 100
local char = script.Parent
local plr = game.Players.LocalPlayer
local Stamina = MaxStamina
local Amount = game.StarterGui.StaminaBar.StaminaBackround.Amount

while wait(1) do
	Stamina -= 1
	print(Stamina)
	plr.PlayerGui.StaminaBar.StaminaBackround.StaminaBar2:TweenSize(UDim2.new(Stamina / MaxStamina, 0,1,0))
	
	Amount.Text = Stamina.. "/" ..MaxStamina
end


Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

It is the amount.text ect part that does not work

You’re attempting to change the Text property of Amount directly. Amount is a reference to a UI element and not the actual TextLabel itself. You need to access the TextLabel component within Amount and then update its Text property

1 Like

The .amount is the text label, I just renamed the text label to amount

Just switch from StarterGui to PlayerGui as you have did in the Amount Variable because StarterGui does give UI when player joins.

1 Like

It’s because you are changing the Template of the ui.

You could do;

local MaxStamina = 100
local char = script.Parent
local plr = game.Players.LocalPlayer
local Stamina = MaxStamina
local Amount = plr.PlayerGui:WaitForChild("StaminaBar").StaminaBackround.Amount

while wait(1) do
	Stamina -= 1
	print(Stamina)
	plr.PlayerGui.StaminaBar.StaminaBackround.StaminaBar2:TweenSize(UDim2.new(Stamina / MaxStamina, 0,1,0))
	
	Amount.Text = Stamina.. "/" ..MaxStamina
end
2 Likes

Thanks, it works perfectly fine now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.