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