This can be accomplished by using a function, and a Debounce Identifier, also, there is a few problems with your code: You are not checking if identifier v is a BasePart, and you forgot an end to the code, for the for loop. Let me explain;
Workspace
Model
Script
Part
Part
Model
And if you called your script;
Workspace
Model
Script
Part
Part
Model
If you leave it as it is, your code will error, and then break, we can fix this by using the if then end statement, also, your code is calling an anonymous [unknown] function, thus may cause an error in the future, let's fix up your code now;
local Debounce = false
function onTouch(hit)
if hit and hit.Parent and not Debounce then
Debounce = true
wait(2)
Debounce = false
end
end
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:connect(onTouch)
end
end
And this also answers your question to how to keep from firing when both parts are stepped on, this uses the same Debounce for each part, and if either one are stepped on, the function will revert it to false before another one fires, prevent from firing when two parts are stepped on at the same time.
Hope this helped!
1 comment
I would re-word the title...