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

TextLabel Text doesn’t change in game?

This is a bit of a short one.

I have a script that concatenates the number value to my TextLabel. The problem is that the text doesn’t change in game, it only changes in the properties menu.

local ammo = script.Parent.Bullets.Value
local gungui = script.Parent.GunGui
local ammotext = gungui.OuterFrame.InnerFrame:WaitForChild(“ammob”)

while true do
    ammotext.Text = (“Ammo: “)..ammo.Value

I have an external script that lowers the Bullets Value each time the player shoots the weapon.

Anybody know why this is happening?

2 comments

0

So, ammo is Number Value or Int Value?

0

Number Value

2 answers

✓ Accepted answer

Firstly, you did not put a end to the loop. And using while true loop in this case isn't suggested at all. You could try this script.

local ammo = script.Parent.Bullets.Value
local gungui = script.Parent.GunGui
local ammotext = gungui.OuterFrame.InnerFrame:WaitForChild(“ammob”)

script.Parent.Bullets:GetPropertyChangedSignal("Value"):Connect()
    ammotext.Text = “Ammo: “.. tostring(ammo) -- You also took value already, so it should be ammo instead of ammo.Value
end)

I assume ammo variable is NumberValue or IntValue. Now, the main problem with TextLabel is that they don't put text if the text is a number and not a string.

To fix it, you can do :

ammotext.Text = "Ammo: "..tostring(ammo.Value)

We used tostring that converts any numerical format is string. The simple difference between a string and a number is :

String is "12345" and Number is 12345.

Lemme know if it helps!

EDIT : I checked in Studio by replicating your code, and you are using '` ``' instead of '" "'.

6 comments

0

Ah. Thanks

0

I searched in Roblox Studio patch notes, and it states that the proble with TextLabel has been fixed. So using tostring() may not be mandatory.

0

It will be helpful if you mark it as the answer.

0

Unfortunately the problem wasn’t fixed

0

So, the value is changing in properties in PlayerGui and not on the player's screen?

0

Yes

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