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

How do I make this function stop after 20 seconds?

Asked by 7 years ago

I tried making it so that when a person touches this part it rains bombs from the sky for 20 seconds and stops after. Since nothing was working, I even tried making a separate brick to stop the function, but I do not know if that works at all..

how will I make the raining stop after 20 seconds?? :(

here is my code

01local bomb = game.ReplicatedStorage.Bomb:clone()
02game.ReplicatedStorage.Bomb.Anchored = false
03local player = game.Players.LocalPlayer
04local bridge = game.Workspace.Bridge
05local bombactivator = game.Workspace.BOMBING
06 
07local function skybombing()
08    while true do
09    local bombClone = bomb:clone()
10    bombClone.Position = Vector3.new(math.random(-500,500),500,math.random(-500,500))
11    bombClone.Parent = game.Workspace
12    bombClone.Anchored = false
13    wait(1)
14    if wait(20) then break
15 
View all 26 lines...

1 answer

Log in to vote
3
Answered by
deris88 146
7 years ago

Hi.

Instead of using while loop use for loop:

1for i = 1, 20 do
2    local bombClone = bomb:clone()
3    bombClone.Position = Vector3.new(math.random(-500,500),500,math.random(-500,500))
4    bombClone.Parent = game.Workspace
5    bombClone.Anchored = false
6    wait(1)
7end
Ad

Answer this question