Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont this script work?

Asked by 8 years ago

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.

0
The touched event is only called when a collision happens, a part resting on another part will not trigger the touched event. DevSean 270 — 8y
0
About the title... "Why wont this script work?", you should probably include small details about your issue within the title. UniversalDreams 205 — 8y

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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
0
It won't work. When I put the first block of code in there are no errors but nothing happens. TheScriptingAccount 90 — 8y
0
Yeah it only works when the blocks are inside of each other not touching. TheScriptingAccount 90 — 8y
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) BlackJPI 2658 — 8y
Ad

Answer this question