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

How do you update a TextLabel with an IntValue?

Asked by 6 years ago

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?

7 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
THX Araknala 14 — 6y
0
No problem! PyccknnXakep 1225 — 6y
0
Could you leave my answer accepted instead of unaccepting and re-accepting it? PyccknnXakep 1225 — 6y
Ad
Log in to vote
0
Answered by
oSyM8V3N 429 Moderation Voter
6 years ago

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

0
Sorry, that doesn't work :/ Araknala 14 — 6y
0
I did Araknala 14 — 6y
Log in to vote
0
Answered by 6 years ago

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
0
I've been doing that, but do i need to put the IntValue in a variable? Araknala 14 — 6y
0
No, you don't need to. This will work just fine. BreadyToCrumble 121 — 6y
0
It didnt work, is there any difference because the TextLabel is in a SurfaceGui Araknala 14 — 6y
0
thx for the help AWE2007WE 0 — 4y
Log in to vote
0
Answered by
dionant 23
6 years ago

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)
0
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. :/ Araknala 14 — 6y
Log in to vote
0
Answered by
ohhel 2
6 years ago
Edited 6 years ago

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!

0
:connect() is deprecated, use :Connect() PyccknnXakep 1225 — 6y
Log in to vote
0
Answered by
INOOBE_YT 387 Moderation Voter
6 years ago

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)
0
thanks!!! Araknala 14 — 6y
Log in to vote
-1
Answered by 6 years ago
Local Location = whereevertheintvalueis
textLabel.Text = Location.intValue.Value''

Answer this question