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

Mass Touched Event?

Asked by
Hibobb 40
10 years ago

Would it be possible to create one script to monitor if any of a group of blocks was touched? This way I wouldn't have to place a script in each part. I have no idea how you would do this but I'll try to explain it with this example that is probably wrong.

for _,v in pairs(workspace.Killers:GetChildren()) do
v.Touched:connect(function(hit)
--etc
end)
end=

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Yes, what you have works.

I would argue that it would probably be better to organize it a little differently, though:

function toucher( hit, part )
    -- hit is the thing touching part,
    -- part is the thing in "Killers"
end

for _, v in pairs(workspace.Killers:GetChildren()) do
    v.Touched:connect( function(hit)
        toucher( hit, v )
    end)
end

Now you keep your definition of what to do outside of the for loop, where it can be a little cleaner.

Ad

Answer this question