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

Need some help with looping Values and Text (?)

Ok soo basically i have an intvalue in workspace and i have a textlabel on a part, i have this script inside of the textlabel

while true do wait(1)
script.Parent.Text = game.Workspace.IntValue.Value
end

it stays on the originally set value as on the studio, how do i fix this?

(i want it to change the textlabel text to the int value every second)

1 comment

0

are you incrementing the IntValue?

2 answers

You're simply missing a +1 so your code would be:

while true do wait(1)
game.Workspace.IntValue.Value = game.Workspace.IntValue.Value+1
script.Parent.Text = game.Workspace.IntValue.Value
end

2 comments

0

It should be game.Workspace.IntValue.Value = game.Workspace.IntValue.Value + 1, then setting the Text to the Value. The value would just stay 1 (assuming the value is 0) if you were to do it like that.

0

Cheers for pointing that out

local value = game.Workspace.IntValue
local tl = script.Parent
tl.Text = value.Value
value.Changed:Connect(function()
wait()
tl.Text = value.Value
end)

if you want to change its value in the same script you can add a Coroutine

 local value = game.Workspace.IntValue
local tl = script.Parent
tl.Text = value.Value
local cor = corountine.wrap(function()
   while wait() do
      wait(1)
      value.Value = value.Value + 1
   end
end)
value.Changed:Connect(function()
wait()
tl.Text = value.Value
end)
cor()

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