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

Touched event firing only when something is moving against it?

Asked by 6 years ago

Alright, so I know this is the normal behavior of the touched event, but I kind of need it to work even if nothing is moving against it. (seeing as most objects are still or anchored)

My friend and I are making a random fire spreading script and the function only runs when stuff is moving, is there some way around this or do we have to stick with it.

(My newbie attempt at trying to get around this)

while wait(2) do
    script.Parent.Touched:connect(yes)
end

1 answer

Log in to vote
1
Answered by 6 years ago

You shouldn’t put events in loops like that. You’re also using deprecated code, make :connect() to :Connect().

From what I understand your question:

You want the fire to spread, not just to touching parts.

If so, here you go. Do keep in mind that SH is not a request site, but I will answer your question because of your attempt.

local touchPart = script.Parent -- the part that will catch other parts on fire

function makefire(part)
    local fire = Instance.new"Fire"
    fire.Parent = part
    -- you can edit other parts like its size, heat etc.
end

for _, v in pairs(game.Workspace:GetChildren()) do
    if v:IsA("BasePart") then -- make sure this is a part
        if (touchPart.Position - v.Position).magnitude <= 10 then
            makefire(v)
        end
    end

    wait(1) -- put wait time here if you don’t want the fire to go on other parts instantly
end
Ad

Answer this question