I made an elevator part that moves players when they touch it.
The issue is that players always move upward instead of moving in the right direction.
I want the part always pushes players in its direction without preventing the player from moving horizontally.
elevator = script.Parent
config = elevator:FindFirstChildWhichIsA("Configuration")
function Touch(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
local root = character:FindFirstChild("HumanoidRootPart")
if not humanoid or not root then return end
if root:FindFirstChild("ElevatorVelocity") then return end
local faceVector = elevator.CFrame.RightVector
local velocity = Instance.new("LinearVelocity", root)
velocity.Name = "ElevatorVelocity"
velocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
velocity.MaxAxesForce = Vector3.new(0, math.huge, 0)
velocity.VectorVelocity = faceVector * config:GetAttribute("Speed")
velocity.Attachment0 = root:FindFirstChildWhichIsA("Attachment") or Instance.new("Attachment", root)
end
function TouchEnded(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
local root = character:FindFirstChild("HumanoidRootPart")
if not humanoid or not root then return end
local elevatorVelocity = root:FindFirstChild("ElevatorVelocity")
if not elevatorVelocity then return end
for _, part in ipairs(workspace:GetPartsInPart(elevator)) do
if part.Parent == hit.Parent then return end
end
elevatorVelocity:Destroy()
end
return function()
elevator.Touched:Connect(Touch)
elevator.TouchEnded:Connect(TouchEnded)
end