Instance.Fire.Touched?

I’m wondering if it’s possible to reference a Fire instance and check if it’s touched; this would allow me to efficiently create a fire-spread system. If this is not possible, what would be the best possible way to spread fires based off being near another part?

This is the FireSpread script and the error that it returns:

-- Firespread

local SSS = game:GetService("ServerScriptService")
local fireSpread = SSS:WaitForChild("FireSpread")
local fireSize = SSS:WaitForChild("FireSize")
local fire = nil

if script.Parent.ClassName == "Fire" then
	fire = script.Parent
end

if fire ~= nil then
	fire.Touched:Connect(function(hit)
		if not hit:FindFirstChild("Fire") and not hit.Parent:FindFirstChild("Humanoid") then
			local newFire = Instance.new("Fire", hit)
			newFire.Name = "Fire"
			
			local fireSpreadClone = fireSpread:Clone()
			fireSpreadClone.Parent = newFire
			fireSpreadClone.Disabled = false
			
			local fireSizeClone = fireSize:CLone()
			fireSizeClone.Parent = newFire
			fireSpreadClone.Disabled = false 
		end
	end)
end

Why don’t you connect the touch function to the BasePart with the fire and spreading fire using a tick-based system that searches for nearby parts to spread fire to? Essentially, the Touched event is ineffective practice for such system. I believe the tick-based raycasting version better than the Touched event since it is very unpredictable.

I’m not very familiar with Raycasting, I’ve looked into the Roblox wikis regarding it and it’s going to take a while to learn it, or at least learning it for looking for nearby objects.

I tried changing it to this:

fire.Parent.Touched:Connect(function(hit)
	if not hit:FindFirstChild("Fire") and not hit.Parent:FindFirstChild("Humanoid") then
		print("Fire touched")
		wait(30)
		local newFire = Instance.new("Fire", hit)
		newFire.Name = "Fire"

However, it’s still not producing any results, this time yielding no errors though.

1 Like

It is likely that the object was already touching something, thus you have to use BasePart:GetTouchingParts() to find each part touching it.

2 Likes

This seems to be a fairly old post but I’ve found that the best way to make a fire spread system would be to use a script that spreads itself throughout touching parts and burning the parent. Put this script inside the part that starts the fire. It will wait a random amount of time then it will burn itself, then clone itself into touching parts and the same happens for those parts and so on. Just make sure the script is named “burn”.

local rand = Random.new()
wait(rand:NextInteger(17, 27)/10)
local f = Instance.new("Fire")
f.Size = script.Parent.Mass
f.Parent=script.Parent
wait(rand:NextInteger(47, 77)/10)
script.Parent.Color = Color3.fromRGB(0, 0, 0);
spawn(function()
	wait(rand:NextInteger(47, 77)/10)
	script.Parent:Destroy()
end)

for i, v in pairs(script.Parent:GetTouchingParts()) do
	if v.Name~="Baseplate" then
		if i < 4 then
			if not v:FindFirstChild("burn") then
				local cl = script:Clone()
				cl.Parent=v
			end
		else
			break
		end
	end
end