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

Why does my sliding door slide out of the building?

Asked by 5 years ago
Edited 5 years ago

Hello! I have been trying for 2 days to get my sliding door to open and close, It opens great but zooms out the building when it closes.. I have looked everywhere and have not found anything and am too lazy to attempt anything else unless this just won't work here is the code:

Debounce = false
script.Parent.PrimaryPart = script.Parent.Center

script.Parent.Parent.Dectector1.Touched:Connect(function()
if not Debounce then
    Debounce = true
for i=6,38 do
    wait()
    script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame + Vector3.new(.1,0,0))
    end
end
wait(2)
for i=6,38 do
    wait()
    script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame -Vector3.new(.1,0,0))
    Debounce = true 
    end 
end) 

Any help would be nice Thanks

1 answer

Log in to vote
0
Answered by
yoyyo75 74
5 years ago
Edited 5 years ago

you don't have a condition to check for debounce when it closes. Im assuming u just need to check for debounce once.

The reason why it zooms is because you could possibly be touching the part multiple times and since you only check for debounce for when it opens, the for loop for the opening would trigger only once because of the not debounce condition. Since the for loop for closing the door isn't in the condition; when you touch it multiple times it would trigger it multiple times thus causing this line

script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame -Vector3.new(.1,0,0))

to happen each time you touch it.

Here is the fix:

Debounce = false
script.Parent.PrimaryPart = script.Parent.Center

script.Parent.Parent.Dectector1.Touched:Connect(function()
if not Debounce then
    Debounce = true
for i=6,38 do
    wait()
    script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame + Vector3.new(.1,0,0))
    end
wait(2)
for i=6,38 do
    wait()
    script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame -Vector3.new(.1,0,0))
    end 

end
end) 

I just moved the end of the if condition after the second for loop instead of before it

Ad

Answer this question