I add 1 value to an IntValue, and so the IntValue's value is supposed to update onto a TextLabel, how am I supposed to do that?
How do you update a TextLabel with an IntValue?
7 answers
To accomplish this, you need to use the Changed event.
So let's say I have a script that increases the IntValue by one every 3 seconds:
while wait(3) do
local int = script.Parent.IntValue
int.Value = int.Value + 1
end
And I have a script that checks if the IntValue has changed, and if so, updates my TextLabel:
script.Parent.IntValue.Changed:Connect(function()
local textLabel = script.Parent.TextLabel
textLabel.Text = script.Parent.IntValue.Value
end)
For more information, consult the Roblox Wiki, but for now, please accept my answer if this helped! Hierarchy here.
Hey, Araknala
If you want to update a TextLabel with an IntValue, in the script make sure to write :
.IntValue.Value
If you put .Value, if the IntValue is 2 you can update it which will also change the TextLabel.
Hope this helps!
~oSy
2 comments
Sorry, that doesn't work :/
I did
In order to update the text displayed on a TextLabel, use the Text property:
http://wiki.roblox.com/index.php?title=API:Class/TextLabel/Text
You can update it by setting it with =, just like a variable.
textLabel.Text = intValue.Value
4 comments
I've been doing that, but do i need to put the IntValue in a variable?
No, you don't need to. This will work just fine.
It didnt work, is there any difference because the TextLabel is in a SurfaceGui
thx for the help
Hello there! You must convert the IntValue to a StringValue
This is what you are looking for:
http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions&redirect=no#tostring
Example:
Let's suppose you have an IntValue named CarWheels, which's value is 4 and it's parent is the same as your script.
You also have a textlabel that must indicate the amount of wheels, with the same parent.
script.Parent.TextLabel.Text = tostring(script.Parent.CarWheels.Value)
1 comment
Ok, let me tell you more about my TextLabel, it is in a SurfaceGui, does that make a difference, because what you said doesn't work. :/
If what you're saying is you want to update a value which will then change the value of a textlabel then surely you'd do:
local int = intvaluelocation
local textlabel = textlabellocation
int.Changed:connect(function()
textlabel.Text = int.Value
end)
Also, don't forget to resize and choose the correct face on your SurfaceGui!
1 comment
:connect() is deprecated, use :Connect()
You need to use the .Changed event. When the IntValue's value changes, the .Changed event will fire and then you can change the TextLabel's text.
IntValue.Changed:Connect(function(Change)
if Change == "Value" then
TextLabel.Text = IntValue.Value
end
end)
1 comment
thanks!!!
Local Location = whereevertheintvalueis
textLabel.Text = Location.intValue.Value''
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
THX
No problem!
Could you leave my answer accepted instead of unaccepting and re-accepting it?