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

how to decrease number value over time?

Asked by 5 years ago

how do you make a script so that every second that a number value decreases by 1? This is for a part with a number value property for when it reaches 0 it turns transparent and cancollide equals false.

1 answer

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

Two different ways to do this a for loop, and a while loop.

local countdown = 30
local block = workspace.Block
for i = countdown, 0, -1 do -- Counts down from 30 to 0, by integrals of -1
wait(1)
if i == 0 then
block.Transparency = 0
block.CanCollide = false
end
end


--OR

while countdown > 0 do
countdown = countdown - 1 
wait(1)
if countdown == 0 then
block.Transparency = 0
block.CanCollide = false
end
end

Edit: To learn more about loops click here.

Ad

Answer this question