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

Code not moving all the parts properly. Is the script correct?

Asked by 3 years ago

Hi there! So i am making a door, which has a union and 3 parts. One of the part has a ClickDetector. And a have scripted it so , when the handle is clicked, the complete door moves 15 vectors right. But the thing is, only the union is moving properly, the rest 3 parts just end up in the centre of the union. Here is the code.

local p1 = script.Parent.right_door.Union
local p2 = script.Parent.right_door.handle_glow
local p3 = script.Parent.right_door.Part
local p4 = script.Parent.right_door.handle

p4.ClickDetector.MouseClick:Connect(function()
    for i = 1,150 do
        wait(0.01)
        p1.Position = p1.Position + Vector3.new(0,0,0.1)
        p2.Position = p1.Position + Vector3.new(0,0,0.1)
        p3.Position = p1.Position + Vector3.new(0,0,0.1)
        p4.Position = p1.Position + Vector3.new(0,0,0.1)
    end
    wait(5)
    for i = 1,150 do
        wait(0.01)
        p1.Position = p1.Position - Vector3.new(0,0,0.1)
        p2.Position = p1.Position - Vector3.new(0,0,0.1)
        p3.Position = p1.Position - Vector3.new(0,0,0.1)
        p4.Position = p1.Position - Vector3.new(0,0,0.1)
    end
end)

Here is the pic of the door. And here is the pic of it moving.

Any help would be highly appreciated!

Answer this question