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

Why does this Part infinitely move on it's X axis?

Asked by 7 years ago
Edited 7 years ago

I'm trying to create a sliding glass door that activates when a player touches an invisible part near the door. While the script is having no problem detecting the player, it continues moving the door without halting. The script located in the transparent detector part:

I should note that the initial position is (-4.54, 8.27, -24.21), which is why I'm having it wait four seconds then move back to that position.

debounce = false
detector = script.Parent
ldoor = detector.Parent.leftDoor

script.Parent.Touched:connect(function(hit)
    if debounce == false then
        debounce = true
        if hit.Parent:FindFirstChild("Humanoid") then
            while ldoor.CFrame ~= Vector3.new(-10.54, 8.27, -24.21) do      
                wait()
                ldoor.CFrame = ldoor.CFrame - Vector3.new(.1,0,0)
            end
            wait(4)
            while ldoor.CFrame ~= Vector3.new(-4.54, 8.27, -24.21) do
                wait()
                ldoor.CFrame = ldoor.CFrame + Vector3.new(.1,0,0)
            end
        end
    end
    debounce = false
end)

Thank you for any and all help!

1 answer

Log in to vote
3
Answered by 7 years ago

In my opinion it is better to have your code for moving the door like this

debounce = false;
detector = script.Parent;
ldoor = detector.Parent.leftDoor;

script.Parent.Touched:connect(function(hit)
    if debounce == false then
        debounce = true;
        if hit.Parent:FindFirstChild("Humanoid") then
            for i = ldoor.CFrame.X, -10.54, -0.1 do
                ldoor.CFrame = CFrame.new(i, ldoor.CFrame.Y, ldoor.CFrame.Z);
                wait();
            end;
            --while ldoor.CFrame ~= Vector3.new(-10.54, 8.27, -24.21) do
                --wait();
                --ldoor.CFrame = ldoor.CFrame - Vector3.new(.1,0,0);
            --end;
            wait(4);
            for i = ldoor.CFrame.X, -4.54, 0.1 do
                ldoor.CFrame = CFrame.new(i, ldoor.CFrame.Y, ldoor.CFrame.Z);
                wait();
            end;
            --while ldoor.CFrame ~= Vector3.new(-4.54, 8.27, -24.21) do
                --wait();
                --ldoor.CFrame = ldoor.CFrame + Vector3.new(.1,0,0);
            --end;
        end;
    end;
    debounce = false;
end);

This way it will move from the point to the new point and will stop when it reaches the point instead of continuing on. I hope this helped and works. If it doesn't please message me back so I can try to help and solve this. If it did work, please accept this as the answer so that others know you have been helped. Again, if it doesn't work, message me or comment and I will work with you until we do get it working. If you have any other non-related questions feel free to ask.

0
Thank you! Perfect! Brinceous 85 — 7y
1
Glad I could help! MrLonely1221 701 — 7y
Ad

Answer this question