Making Disasters

So I have a module with the functions StartDisaster and EndDisaster, however I do not know how I can make them work well. I managed to make the StartDisaster however it didn’t work well and I couldn’t get a way for it to end.

module
local module = {}

function module.StartDisaster()
	local DID = game.ServerStorage.DisasterID
	
	if DID == 1 then
		--// Raining Bombs
	end
end

function module.EndDisaster()
	local DID = game.ServerStorage.DisasterID
	
	if DID == 1 then
		--// End Raining Bombs
	end
end

return module

Each disaster will have a loop of somesort, so I need to workaround that - I was thinking coroutine’s but I couldn’t get them to work as I have 0 experience with them.

For my first disaster - it’s raining bombs. I already have the function to spawn one in:

local function SpawnRainingBomb()
	-- Setup zone
	local zonePlus = game:GetService("ReplicatedStorage").Zone
	local Zone = require(game:GetService("ReplicatedStorage").Zone)
	local Maid = require(zonePlus.Maid)
	local group = workspace.MapHitbox
	local zone = Zone.new(group)
	local maid = Maid.new()
	local heartbeat = game:GetService("RunService").Heartbeat

	local randomVector = zone:getRandomPoint()
	local part = game.ReplicatedStorage.Bomb:Clone()
	part.Anchored = false
	part.CanCollide = true
	part.Transparency = 0
	part.CFrame = CFrame.new(randomVector)
	part.Parent = workspace
	part.Transparency = 0
	maid:give(part)

	coroutine.wrap(function()
		wait(1)
		local explo = Instance.new('Explosion')
		explo.Parent = part
		explo.Visible = true
		part.Transparency = 1
		explo.BlastPressure = 2000000
		explo.BlastRadius = 12
		explo.DestroyJointRadiusPercent = 1
		explo.Position = part.Position

		local sound = Instance.new("Sound")
		sound.SoundId = "rbxassetid://7244429398"
		sound.Parent = part
		sound.Volume = 1
		sound:play()

		print('exploded')
	end)()
end

But it’s the actual loop to make the disaster run that is the issue

Can anyone help?

1 Like