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

C-Frame doing random movements, why?

Asked by 8 years ago

So I have a script that moves a door forward, then to the side, but it's meant to stay there until the handle is re-clicked, but it moves backwards afterwards, but I don't know why...

function click()
if(script.Parent.Status.Value)=="Closed" then
script.Parent.Status.Value="Opening"
local sidemoves=2
local sidespeed=0.1
for i=1,sidemoves do
wait(0.01)
script.Parent.PLT:SetPrimaryPartCFrame(script.Parent.PLT.PrimaryPart.CFrame + Vector3.new(-sidespeed,0,0));
end
wait(0.5)
local movements=91
local speed=0.1
for i=1,movements do
wait(0.01)
script.Parent.PLT:SetPrimaryPartCFrame(script.Parent.PLT.PrimaryPart.CFrame + Vector3.new(0,0,-speed));
end
script.Parent.Status.Value="Open"


--negative movement
elseif(script.Parent.Status.Value)=="Open" then
script.Parent.Status.Value="Closing"

local movements=91
local speed=0.1
for i=1,movements do
wait(0.01)
script.Parent.PLT:SetPrimaryPartCFrame(script.Parent.PLT.PrimaryPart.CFrame + Vector3.new(0,0,speed));
end
script.Parent.Status.Value="Closed"
end
wait(0.5)
local sidemoves=2
local sidespeed=0.1
for i=1,sidemoves do
wait(0.01)
script.Parent.PLT:SetPrimaryPartCFrame(script.Parent.PLT.PrimaryPart.CFrame + Vector3.new(sidespeed,0,0));
end

end
script.Parent.PLT.Union.ClickDetector.MouseClick:connect(click)

Answer this question