Need help with fire script

I am making a cooking game and when a food is burnt, I want the cooker to set on fire. (this already works). The problem is, I want the parts that are touching the part that is on fire to also be on fire.
For example:
RobloxScreenShot20210415_132635230
The cooker is on fire. After a few seconds I want the bin to be on fire. Then after another few seconds I want the counter to be on fire. Here is the script:

					local function fire(PART)
						print(PART.Name)
						local touchingparts = PART:GetTouchingParts()
						local fclone = script.FireParticles:Clone()
						fclone.Parent = PART
						print("made fire")

						wait(5)
						for  _,Part in pairs(touchingparts) do
						
								if Part:GetAttribute("Interactive")  == true then
								if not Part:FindFirstChild("FireParticles") then
										Part:SetAttribute("Status","Burning")
										local FIRE = script.FireParticles:Clone()
									FIRE.Parent = Part
									print(Part.Name)
								
										fire(Part)
									
								end
							end
						end


					end
					
					fire(part)
1 Like

You can detect the part that is burning what it is touching it and start to give it fire particles.

1 Like

Instead of burning them all from one script, you could pretend like the script is the fire.
What I mean is, The burning part has the script in it which gives the part the particles and set the attributes.
Then the fire script checks if there is anything touching which it can burn and then inserts itself into this part.
Like a virus.
Only need to change some things in your script, i did this for you:

local part = script.Parent
local function fire(PART)
	print(PART.Name)
        part:SetAttribute("Status","Burning")
	local touchingparts = PART:GetTouchingParts()
	local color = BrickColor.new("Really red")
	PART.BrickColor = color
	print("made fire")

	wait(5)
	for  _,Part in pairs(touchingparts) do
		if Part:GetAttribute("Interactive")then
			if Part:GetAttribute("Status") ~= "Burning" then
				local fire = script:Clone()
				fire.Parent = Part
			end
		end
	end


end

fire(part)

like you can see, I changed the particles with the color, because of testing at my own studio, you can change that back.
I also changed the if not Part: FindFirstChild("FireParticles") then you can keep it or change it, both should work.

Like this, the Fire script inserts itself into the blocks touching it and runs itself automatically.
To stop this you could destroy the script to prevent the spreading.

2 Likes

Yes, but you also probably want to keep track of all the fire scripts using CollectionService | Roblox Creator Documentation. Otherwise things can get out of hand. You could also use CollectionService to keep track of what parts are able to be set on fire and what parts are not. The problem is that it’s hard to detect the size and amount of particles you need to use for each individual part. What makes one part look on fire may make another part look like it’s just emitting embers.

3 Likes