Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why wont this script work?

It's supposed to spread fire to the brick that it's touching but it wont work on bricks that it's already in contact with.

local Target = script.Parent.Spreadable

function makefire(parent)
	local fire = Instance.new("Fire")
	fire.Parent = parent
end

makefire(Target)


Target.Touched:connect(function(spreadto)
	wait(1)
	makefire(spreadto)
end)

It only would spread to the other bricks when I moved them away and back onto the part. Help? Thanks.

2 comments

0

The touched event is only called when a collision happens, a part resting on another part will not trigger the touched event.

0

About the title... "Why wont this script work?", you should probably include small details about your issue within the title.

1 answer

You can use the method GetTouchingParts() to set fire to the parts that are initially touching the fire without moving:

######Assuming your function makeFire and Target are defined

local touching = Target:GetTouchingParts()

for _, part in next, touching do
	wait(1)
	makeFire(part)
end

However, this will wait 1 second everytime it checks a part. So if there are 10 touching parts, the 10th part will wait 10 seconds.

To fix this we can use the function spawn (or coroutines, which ever you prefer) to run the desired function on a separate thread:

local touching = Target:GetTouchingParts()

for _, part in next, touching do
	spawn(function()
		wait(1)
		makeFire(part)
	end)
end

3 comments

0

It won't work. When I put the first block of code in there are no errors but nothing happens.

0

Yeah it only works when the blocks are inside of each other not touching.

0

Oh, well the only other options I can think of is checking the magnitude or Region3 (or use a Region 3 to restrict your magnitude search)

This discussion is preserved as it was. New answers, comments, and votes are closed.