I've been working on this game for a few days now and I just got a fire script for it. It works and everything but when I put out the fire the script doesn't know when the fire is put out. So I tried looking up how to repeat the script to keep doing the same thing over and over again. But I couldn't find anything useful can someone please help me with my problem. I do not know how to script so this is my last chance of finding success.

This is the script I want repeating itself BUT I want it to repeat itself in a certain amount of time so I don't have multiple fires at once.

wait(150)

local Buildings = {}

for i,v in pairs(workspace:GetChildren()) do
	if v:IsA("Model") and v:FindFirstChild("FireActive") and v:FindFirstChild("SoundPart") then
		table.insert(Buildings, v)
	end
end

function Ignite(part)
	local realFire = Instance.new("Fire", part)
	realFire.Size = 20
	realFire.Heat = 20
	realFire.Enabled = false
	for _,particle in pairs(script.FireParticles:GetChildren()) do
			local newparticle = particle:Clone()
			newparticle.Parent = part
			newparticle.Enabled = true
			if newparticle.Name == "FireP" and newparticle:IsA("ParticleEmitter") then
				local factor = (part.Size.X)*(part.Size.Y)*(part.Size.Z)*0.4 + 1.5
				newparticle.Rate = factor
			elseif newparticle:IsA("ParticleEmitter") then
				local factor = (part.Size.X)*(part.Size.Y)*(part.Size.Z)*0.13 + 1.5
				newparticle.Rate = factor
			end
	end
	script.FireExtinguishScript:clone().Parent = part
	part.FireExtinguishScript.Disabled = false
end

function SetFire(building)
	local RandomNumber = math.random(1,3)
	if RandomNumber == 1 then --large fire
		print("Starting Large Fire: "..building.Name)
		for i,part in pairs(building:GetChildren()) do
			wait(0.2)
			 if part:IsA("BasePart") and part.Name ~= "SoundPart" and part.Name ~= "SmokePart" and part.Name ~= "NonFlammable"  then
				Ignite(part)
			elseif part:IsA("Model") and part.Name == "COLOR" then
				for i,v in pairs(part:GetChildren())do if v:IsA("BasePart") and part.Name ~= "SoundPart" and part.Name ~= "SmokePart" and part.Name ~= "NonFlammable"  then Ignite(v) end end
			elseif part.Name == "SmokePart" then
				local Newsmoke = script.FireParticles.Smoke:Clone()
				Newsmoke.Parent = part
				Newsmoke.Rate = (part.Size.X)*(part.Size.Y)*(part.Size.Z)*0.3 + 1.5
				Newsmoke.Enabled = true
			elseif part.Name == "SoundPart" then
				script.FireAlarm:clone().Parent = part
				part.FireAlarm.Script.Disabled = false
			end
		end
	else --small fire 
		print("Starting Small Fire: "..building.Name)
		local MainPart = nil
		local function pickMainPart()
			local MainPartNumber = math.random(1,#building:GetChildren())
			local MainPart2 = building:GetChildren()[MainPartNumber]
			if MainPart2:IsA("BasePart") then 
				MainPart = MainPart2
			else
				pickMainPart()
			end
		end
		pickMainPart()
		for i,part in pairs(building:GetChildren()) do
			wait(0.1)
			if part:IsA"BasePart" and (part.Position - MainPart.Position).magnitude < math.random(10,25) and part.Name ~= "SoundPart" and part.Name ~= "SmokePart" and part.Name ~= "NonFlammable" then
				Ignite(part)
			elseif part:IsA("Model") and part.Name == "COLOR" then
				for i,v in pairs(part:GetChildren())do 
					if v:IsA("BasePart") and (v.Position - MainPart.Position).magnitude < math.random(10,25) then Ignite(v) end 
				end
			elseif part.Name == "SmokePart" then
				--no smoke
			elseif part.Name == "SoundPart" then
				script.FireAlarm:clone().Parent = part
				part.FireAlarm.Script.Disabled = false
			end
		end
	end
	--set off server things/911 call here:
	game.ReplicatedStorage.GameplayUIs.Radio.fireCall:Fire(building.Name)
	building.FireActive.Value = true
end

function RemoveFire(building)
	for i,part in pairs(building:GetChildren()) do
		if part.Name ~= "SoundPart"  then
			for i,child in pairs(part:GetChildren()) do
				if child:IsA("ParticleEmitter") or child.Name == "FireLight" then
					child:Destroy()
				end
			end
			if part:FindFirstChild("Fire") then part.Fire:Destroy() end
		elseif part.Name == "COLOR" and part:IsA("Model") then
			for i,p in pairs (part:GetChildren()) do
				for i,child in pairs(p:GetChildren()) do
					if child:IsA("ParticleEmitter") or child.Name == "FireLight" then
						child:Destroy()
					end
				end
				if p:FindFirstChild("Fire") then p.Fire:Destroy() end
			end
		elseif part.Name == "SoundPart" then
			if part:FindFirstChild("WhiteLight") then part.WhiteLight:Destroy() end
			if part:FindFirstChild("FireAlarm") then part.FireAlarm:Destroy() end
			if part:FindFirstChild("FireSound") then part.FireSound:Destroy() end
		end
	end
	building.FireActive.Value = false
end

function CheckFireStatus(building)
	local count = 0
	for i,v in pairs(building:GetChildren()) do
		if v:findFirstChild("Fire") then
			count = count + 1
		end
	end
	if count == 0 then
		RemoveFire(building)
		building.FireActive.Value = false
	end
end

		
--Start fires:
while wait(100) do
	local firefighters = 0
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.TeamColor == BrickColor.new("Maroon") then
			firefighters = firefighters + 1
		end
	end
	if firefighters >= 1 then
		local RandomNumber = math.random(1, #Buildings)
		local RandomBuilding = Buildings[RandomNumber]
		SetFire(RandomBuilding)
		wait(180)--save resources 
		repeat CheckFireStatus(RandomBuilding) wait(30) until RandomBuilding.FireActive.Value == false
		wait(math.random(20*60, 25*60)) 
	end
end

3 comments

0

use codeblocks next time please

0

repeat -- fire code -- until --fire over code --

0

you coded all of this?