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 6 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

local bomb = game.ReplicatedStorage.Bomb:clone()
game.ReplicatedStorage.Bomb.Anchored = false
local player = game.Players.LocalPlayer
local bridge = game.Workspace.Bridge
local bombactivator = game.Workspace.BOMBING

local function skybombing()
    while true do
    local bombClone = bomb:clone()
    bombClone.Position = Vector3.new(math.random(-500,500),500,math.random(-500,500))
    bombClone.Parent = game.Workspace
    bombClone.Anchored = false
    wait(1)
    if wait(20) then break

    end
    end
end

bombactivator.Touched:Connect(function(Touched)
    if Touched.Parent:FindFirstChild("Humanoid") then
        wait(1)
        bombactivator.BrickColor = BrickColor.Red()
        skybombing()
    end
end)



1 answer

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

Hi.

Instead of using while loop use for loop:

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

Answer this question