I am making a lift and need help moving it up and down. I used Position
to move the primary part of the lift up and down when I press a certain button, but it did not move the lift components. So, I used CFrame and it worked. The problem is the lift rotates as it goes up. I think this is because of the CFrame LookVector. What look vector should I use so the lift does not spin whilst moving up and down?
Edit: Video of problem.
robloxapp-20211205-0709523.wmv (935.1 KB)
Edit: Main code.
local placeholderDoors = script.Parent.Parent:WaitForChild("Placeholder_Doors")
local isMoving = script.Parent.Is_Moving
local floorLevels = workspace:WaitForChild("Floor_Levels")
local currentFloor = script.Parent.Current_Floor
local buttons = script.Parent:WaitForChild("Buttons"):GetChildren()
local movingFloor = script.Parent.PrimaryPart
local tweenservice = game:GetService("TweenService")
for i, v in pairs(buttons) do
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = v
clickDetector.MouseClick:Connect(function(player)
if isMoving.Value == true then
--they must wait
else
local moveTime = math.sqrt((script.Parent.PrimaryPart.Position-player.Character.HumanoidRootPart.Position).Magnitude)
print(moveTime)
--tween the elevator to their position
local tweenInfo = TweenInfo.new(
moveTime,
Enum.EasingStyle.Linear
)
local floor = script.Parent.Moving_Floor
print(floor)
print(v.Name)
local position = Vector3.new(floor.Position.X, floorLevels:WaitForChild(v.Name).Position.Y, floor.Position.Z)
local vector = floor.CFrame.LookVector
local tween = tweenservice:Create(floor, tweenInfo, {CFrame = CFrame.new(position, vector)})
tween:Play()
isMoving.Value = true
wait(moveTime)
isMoving.Value = false
local splitString = string.split(v.Name, "_")
local number = splitString[2]
currentFloor.Value = tonumber(number)
end
end)
end