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

Help with a IntValue.Changed?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

I am gonna be working on a minigame type game and I use to know how to do this type of script but I forgot. So I am not sure the best way to write this kind of loop and make the Value change ever sec. I do have a ".Changed" event in a TextLabel too.

while true do
    for i = 1,20 do
        Val = game.Workspace:WaitForChild("GameTime")
        Val.Value = i + 1
        wait(1)
    end
end

1 answer

Log in to vote
2
Answered by 8 years ago

.Changed will fire every time the value of a property changes. In a TextLabel it will fire when the text is shows has changed etc.

To change a value you need to do something like this. (Note that you don't need that while loop)

 for i = 1,20 do
        Val = game.Workspace:WaitForChild("GameTime")
        Val.Value = Val.Value + 1 --Take the value that GameTime had before and add 1.
        wait(1)
    end

What you are currently doing will result in the value of Val ascending from 2. You could also do this

    for i = 1,20 do
        Val = game.Workspace:WaitForChild("GameTime")
        Val.Value = i -- i will increase with every loop of the for, so you don't need to add one to it.
        wait(1)
    end

In the first piece of code, I used the "for i=1,20" part to just say how many times the loop should run. In the second piece of code I used that part to actually change the value of Val to that number (i)

It is up to you how you increment your value every second, as you can do it in either of the two ways.

Ad

Answer this question