How would I stop my disaster selector choosing disasters when the round ends?

My problem is pretty annoying. I’ve developed a round system and a disaster selector for my game, and they both work. Only issue is, once the round has finished, the disaster selector won’t stop selecting disasters, therefore, destroying the newly generated map. My question is, how would I make sure that the disaster selector only starts the disasters when the round is actually in progress?

Note
I did try send a boolean across to the selector script using a bindable event, so it would only run the conditionals once the boolean was set to true, but that doesn’t seem to be effective.

Disaster Selector

local TweenService = game:GetService("TweenService")
local function SelectTile()
	local Tiles = workspace["Spleef Map"]:GetChildren()
	local ActualTiles = {}
	for i, v in pairs(Tiles) do
		if v:IsA("Part") then
			table.insert(ActualTiles,#ActualTiles+1, v)
		end
	end
	return ActualTiles[math.random(1, #ActualTiles)]
end

function Crumble()
	local toCrumble = {}
	for i = 1, 9, 1 do
		table.insert(toCrumble, #toCrumble+1, SelectTile())
	end
	for i, v in pairs(toCrumble) do
		delay(5, function()
			v:Destroy()
		end)
	end
end

function Bomb()
	local toCrumble = {}
	for i = 1, 9, 1 do
		table.insert(toCrumble, #toCrumble+1, SelectTile())
	end
	for i, v in pairs(toCrumble) do
		wait(3)

		local explosion = Instance.new("Explosion", v)
		explosion.Position = v.Position
		script.Explosion:Play()
		wait(.5)
		v:Destroy()
		wait()
		explosion:Destroy()
	end
end

function UFO()

	local ToDestroy = {}
	local clone = game.ServerStorage.Disasters.UFO:Clone()
	clone.Parent = workspace
	for i = 1, 9, 1 do
		table.insert(ToDestroy, #ToDestroy+1, SelectTile())
	end
	for i, v in pairs(ToDestroy) do
		clone.Handle.Position = Vector3.new(-121.797, 116.918, -124.093)
		clone.Handle.Anchored = true
		local Explosion = Instance.new("Explosion", v)
		Explosion.Position = v.Position
		wait(1)
		script.Explosion:Play()
		Explosion:Destroy()
		v:Destroy()
	end
	delay(1, function()
		clone:Destroy()
	end)
end

function GearThem()
	local Players = game.Players:GetPlayers()
	for i, v in pairs(Players) do
		if v:WaitForChild("CRW").Value then
			local gearFolder = game:GetService("ServerStorage").GearFolder:GetChildren()
			local backpack = v.Backpack
			if backpack then
				local chosenToolClone = gearFolder[math.random(1, #gearFolder)]:Clone()
				if backpack:FindFirstChildOfClass("Tool") then
					return
				else
					chosenToolClone.Parent = backpack
				end
			end
		else
			return
		end
	end
end

function FIRE()
	local tb = {}
	for i = 1, 4, 1 do
		table.insert(tb, #tb+1, SelectTile())
	end

	for i, v in pairs(tb) do
		local fire = Instance.new("Fire")
		fire.Parent = v
		fire.Size = 20
	end
	delay(2, function()
		for i, v in pairs(workspace:GetDescendants()) do
			if v:IsA("Fire") then
				v.Parent:Destroy()				
			end
		end
	end)
end
---SEE THE 2ND PARAMETER, THAT WAS THE BOOL MENTIONED IN THE NOTE PART.
game.ServerStorage.DisasterEvent.Event:Connect(function(number, bool)
	if bool then 
		local tbl_disasters = {"UFO", "GearThem", "Bomb", "Crumble"}
		local chosenDisasters = {}
		local chosen
		for i  = 1, number do
			repeat 
				chosen = tbl_disasters[math.random(1, #tbl_disasters)]
				wait(1)
			until not table.find(chosenDisasters, chosen)
			table.insert(chosenDisasters, #chosenDisasters+1, chosen)	
		end
		for _, v in pairs(chosenDisasters) do
			print(string.lower(v))
		end
		while bool do
			while wait(4) do
				local ChosenRnd = chosenDisasters[math.random(1,#chosenDisasters)]
				print("Currently: "..string.lower(ChosenRnd))
				----CHOOSING DISASTERS----
				if ChosenRnd == "GearThem"then
					GearThem()
				elseif ChosenRnd == "UFO" then
					UFO()
				elseif ChosenRnd == "Bomb" then
					Bomb()
				elseif ChosenRnd == "Crumble" then
					Crumble()	
				elseif  chosenDisasters == "FIRE" then
					FIRE()
					----Im trying to work out here, how to break the loop when the bool is false.
					

				end
			end
		end

	end

end)

Round System

local roundtime = game.ReplicatedStorage.RoundTime
local inter =  game.ReplicatedStorage:WaitForChild("Intermission")
local collectionService = game:GetService("CollectionService")
local numberOfDisasters

inter.Value = 30
roundtime.Value = 120
function TagAllPlayers(Tag)
	for i, v in pairs(game.Players:GetPlayers())do
		collectionService:AddTag(v, Tag)
	end
end

function CheckPlayersTag(Tag)
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		local Character = v.Character
		if Character then
			if Character:WaitForChild("Humanoid").Health == 0 then
				v:WaitForChild("CRW").Value = false
				collectionService:RemoveTag(v, "Alive")
				collectionService:AddTag(v, "Dead")
			end
		end
	end
end
function TeleportPlayersBackToLobby()
	local tp_BackTiles = workspace.TeleportBackTiles:GetChildren()
	for i, v in pairs(game.Players:GetPlayers()) do
		local TileChosen = tp_BackTiles[math.random(1, #tp_BackTiles)]
		local HRP = v.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part") then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		end
	end
end

function TeleportPlayers()
	local Tiles = workspace["Spleef Map"]:GetChildren()
	for index, Player in pairs(game:GetService("Players"):GetPlayers()) do
		local CanRecieveWeapons = Instance.new("BoolValue", Player)
		CanRecieveWeapons.Name = "CRW"
		CanRecieveWeapons.Value =true
		local TileChosen = Tiles[math.random(1, #Tiles)]
		local HRP = Player.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part" ) then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		end
	end
end

function CheckNum_Players()
	local Players = game.Players:GetPlayers()
	if #Players >= 0 then
		return true
	else
		return false
	end
end

while true do
	local Ready = false
	Ready = CheckNum_Players()
	if Ready then
		game.ReplicatedStorage.IsIntermission.Value = true
		for i = 30, 0, -1 do
			inter.Value = i
			wait(1)
		end
		numberOfDisasters = math.random(1, 4)
		local disasterinfo = game.ReplicatedStorage.disasterInfo
		disasterinfo:FireAllClients(numberOfDisasters)
		wait(6)
		if inter.Value == 0 then
			game.ReplicatedStorage.IsIntermission.Value = false

			TeleportPlayers()
			TagAllPlayers("Alive")
			game.ServerStorage.DisasterEvent:Fire(numberOfDisasters, true)
			for i = 120, 0, -1 do
				roundtime.Value = i
				CheckPlayersTag("Alive")
				wait(1)
			end
			if roundtime.Value == 0 then
				local Winners = {}
				for i, v in pairs(collectionService:GetTagged("Alive")) do
					table.insert(Winners, #Winners+1, v)
					collectionService:RemoveTag(v, "Alive")
				end

				for i, v in pairs(Winners) do
					local chosenAmount
					local function CheckPermission(plr)
						if plr:IsInGroup(7895196)then
							return true
						end

					end

					print(v.Name.." Was A Winner")
					if CheckPermission(v) then
						chosenAmount = 60
					else
						chosenAmount = 50
					end
					v:WaitForChild("SpleefCoins").Value += chosenAmount
					v:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
					game.ReplicatedStorage.ShowMoneyEffect:FireClient(v,chosenAmount)
				end
				game.ReplicatedStorage.showWinnersEvent:FireAllClients(Winners)
				game.ReplicatedStorage.IsIntermission.Value = true

				game.ServerStorage.DisasterEvent:Fire(nil, false)
				TeleportPlayersBackToLobby()
				workspace["Spleef Map"]:Destroy()
				delay(2, function()
					print("Regenerating")
					local Clone = game.ServerStorage:WaitForChild("Spleef Map"):Clone()
					local chosenColor = BrickColor.Random()
					for i, v in pairs(Clone:GetChildren()) do
						v.BrickColor = chosenColor
					end
					local ss = game.ServerStorage.PartTagger:Clone()
					Clone.Parent = workspace
					ss.Parent = Clone
				end)
			end
		end
	else
		print("Not enough players to start")
	end
	wait(1)
end

In case you need anything to work with, I have an actual boolValue in replicatedStorage to switch to true when it is intermission, and false when not.

I did try doing this:

	while bool do
			while wait(4) do
				local ChosenRnd = chosenDisasters[math.random(1,#chosenDisasters)]
				print("Currently: "..string.lower(ChosenRnd))
				----CHOOSING DISASTERS----
				if ChosenRnd == "GearThem"then
					GearThem()
				elseif ChosenRnd == "UFO" then
					UFO()
				elseif ChosenRnd == "Bomb" then
					Bomb()
				elseif ChosenRnd == "Crumble" then
					Crumble()	
				elseif  chosenDisasters == "FIRE" then
					FIRE()
					----Im trying to work out here, how to break the loop when the bool is false.
					game.ReplicatedStorage.IsIntermission:GetPropertyChangedSignal("Value"):Connect(function()
						if game.ReplicatedStorage.IsIntermission.Value == true then
							break
						end
					end)
				

				end

but then it says ’ break’ has to be in a loop, which I know but I’m unsure what else there is to do

wait so do you want it to just completely stop the script permanently or temporarily

Temporarily, until the round restarts

what do you mean by restart? does the script not keep picking the disasters?
I have a game with a disaster script that keeps picking disasters every time one ends and cleans up the map and disasters before the next one starts.
would there be any reason for you to want to just completely stop disasters from happening even though they will only happen again?

I just want the selector to pause during the intermission, before starting again once the round system starts a new round. Effectively just for it to be in sync with the round system script

Plus, my game isn’t solely a disaster game. It just includes some disasters in it.

why dont you make the while bool a while true do and make it so that it checks if the bool is true of false with an if statement and if true then choose the disasters then if false dont do it
I think that would work since it constantly checks the bool
Im thinking something like this

while true do
if bool == true then
--make the script choose disasters
elseif bool == false then
print("Bool is false, could not choose disasters")
end

so what that does is constantly check if the bool is true of false then if its true then choose the disasters and if false dont do anything
Don’t use that since its just an example

1 Like

Maybe this will work
I could be wrong though since this could have some errors since im not doing this in studio rn

   while true do
    if bool = true then
    			while wait(4) do
    				local ChosenRnd = chosenDisasters[math.random(1,#chosenDisasters)]
    				print("Currently: "..string.lower(ChosenRnd))
    				----CHOOSING DISASTERS----
    				if ChosenRnd == "GearThem"then
    					GearThem()
    				elseif ChosenRnd == "UFO" then
    					UFO()
    				elseif ChosenRnd == "Bomb" then
    					Bomb()
    				elseif ChosenRnd == "Crumble" then
    					Crumble()	
    				elseif  chosenDisasters == "FIRE" then
    					FIRE()
    end)
    elseif bool = false then
    break
    						end --you should probably add a wait just in case
    					end
1 Like

hmm maybe that would not work since it would break the loop and not just the bool loop

I’m currently testing it now anyway.

EDIT: IT WORKS! Thanks!

Maybe something like this will work

  while true do
if bool == true then
  while bool do
    if bool == true then
    			while wait(4) do
    				local ChosenRnd = chosenDisasters[math.random(1,#chosenDisasters)]
    				print("Currently: "..string.lower(ChosenRnd))
    				----CHOOSING DISASTERS----
    				if ChosenRnd == "GearThem"then
    					GearThem()
    				elseif ChosenRnd == "UFO" then
    					UFO()
    				elseif ChosenRnd == "Bomb" then
    					Bomb()
    				elseif ChosenRnd == "Crumble" then
    					Crumble()	
    				elseif  chosenDisasters == "FIRE" then
    					FIRE()
    end)
    elseif bool == false then
    break
    						end --you should probably add a wait just in case
    					elseif bool == false then
print("bool is = to false, could not select disasters")
end
end

oh it works? okay if it works the way you want it to then ignore my other post.

1 Like