How to see countdown subtracting by 1 in the output display?

Hello! I need help with the script I made earlier on… As you can clearly see that I’m not a pro scripter just a beginner new to scripting. I wanted to make a part that stays in the air for 30s before Anchored is turn to false and the countdown can also be seen Subtracting by 1 in the output.


UnSofia.Anchored = true



wait(30)

print(30)
print(29)
print(28)
print(27)
print(26)
print(25)
print(24)
print(23)
print(22)
print(21)
print(20)
print(19)
print(18)
print(17)
print(16)
print(15)
print(14)
print(13)
print(12)
print(11)
print(10)
print(9)
print(8)
print(7)
print(6)
print(5)
print(4)
print(3)
print(2)
print(1)
	

UnSofia.Anchored = false
-- 

Sorry if my questions are not clear to you :C

> Any help will be highly appreciated!<

Better yet, why not use a while true loop?

local Time = 30

local function Timer()   -- Timer function
    print(Time)
end

while true do
    Timer()   -- Function is fired
    Time -= 1 -- Subtract 1 from the time variables
    wait(1)   -- Every one second this while true loop "fires"
end
1 Like

The best approach here would be to use a numerical for loop (see here for more info) to count down from 30 to 0 with a 1 second wait inbetween each deincrement.

ie.

for i = 30, 0, -1 do --// 30 = start, 0 = end, -1 = deincrementor 
    print(i);
    wait(1);
end

--// Do what you need to after the countdown
3 Likes

This topic has been covered up already, consider doing some research before making this topic. The people above this comment has a lot of good point and good solutions for you to mark.