I've got this sliding door script, and it is meant to move the Door down 15 studs, wait 3 seconds, then move it back up when a brick is touched. The only problem is that when I touch it, it's Y coordinates go all the way down to about -700,000. I've discovered that the problem is that it is registering that I am hitting the brick hundreds of times, rather than 1 like I want. I tried implementing my debounce to help this, but I still have the same problem.
What is my problem?
function onTouched(hit)
debounce = script.Parent.Debounce.Value
player = hit.Parent
if hit.Parent ~= nil and debounce == false then
debounce = true
pos = 33.5
for i=0.1,150 do
wait(0.01)
script.Parent.Parent.Door.CFrame = script.Parent.Parent.Door.CFrame * CFrame.new(0, pos - i, 0)
pos = pos - i
end
wait(3)
pos1 = 18.5
for i=0.1,150 do
wait(0.01)
script.Parent.Parent.Door.CFrame = script.Parent.Parent.Door.CFrame * CFrame.new(0, pos1 + i, 0)
pos1 = pos1 + i
end
debounce = false
end
end
script.Parent.Touched:connect(onTouched)

1 comment
I edited my answer to explain what I meant better.