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

How do you update a TextLabel with an IntValue?

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

✓ Accepted answer

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.

3 comments

0

THX

0

No problem!

0

Could you leave my answer accepted instead of unaccepting and re-accepting it?

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

0

Sorry, that doesn't work :/

0

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

0

I've been doing that, but do i need to put the IntValue in a variable?

0

No, you don't need to. This will work just fine.

0

It didnt work, is there any difference because the TextLabel is in a SurfaceGui

0

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

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. :/

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

0

: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

0

thanks!!!

Local Location = whereevertheintvalueis
textLabel.Text = Location.intValue.Value''

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