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

Need some help with looping Values and Text (?)

Asked by 5 years ago

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)

0
are you incrementing the IntValue? greatneil80 2647 — 5y

2 answers

Log in to vote
1
Answered by
xg1y 41
5 years ago
Edited 5 years ago

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
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. PhantomVisual 992 — 5y
0
Cheers for pointing that out xg1y 41 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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()

Answer this question