Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

TextLabel Text doesn’t change in game?

Asked by 3 years ago

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?

0
So, ammo is Number Value or Int Value? BestCreativeBoy 1395 — 3y
0
Number Value Pancaken8 3 — 3y

2 answers

Log in to vote
0
Answered by
Techyfied 114
3 years ago
Edited 3 years ago

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)
Ad
Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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 '" "'.

0
Ah. Thanks Pancaken8 3 — 3y
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. BestCreativeBoy 1395 — 3y
0
It will be helpful if you mark it as the answer. BestCreativeBoy 1395 — 3y
0
Unfortunately the problem wasn’t fixed Pancaken8 3 — 3y
View all comments (2 more)
0
So, the value is changing in properties in PlayerGui and not on the player's screen? BestCreativeBoy 1395 — 3y
0
Yes Pancaken8 3 — 3y

Answer this question