# How can I make the player go in other directions with LinearVelocity?

So, I have this elevator in my difficulty chart obby, it makes the player go upwards when they jump into it, I used LinearVelocity.
But the problem is, when the player is going upwards, I can’t control the XZ movements of the player.
Can somebody help me?
Here’s the code:

``````local hrp = script.Parent.HumanoidRootPart
if not hrp:FindFirstChild("LinearVelocity") then
local velocity = Instance.new("LinearVelocity", hrp)

velocity.Attachment0 = hrp.RootAttachment

velocity.VectorVelocity = Vector3.new(0, 5, 0)

if hit.CFrame.UpVector.X ~= 0 then
velocity.VectorVelocity = Vector3.new(hit.CFrame.UpVector.X, velocity.VectorVelocity.Y, velocity.VectorVelocity.Z)
end

if hit.CFrame.UpVector.Z ~= 0 then
velocity.VectorVelocity = Vector3.new(velocity.VectorVelocity.X, velocity.VectorVelocity.Y, hit.CFrame.UpVector.Z)
end
end
``````

It’s inside StarterCharacterScripts to check if the player touched the elevator

You can just change the VectorVelocity to have X and Z components:

``````velocity.VectorVelocity = Vector3.new(10, 5, 10)
``````

But that would make the player move without him pressing the keys.
I want that the player can move freely in the XZ direction.

Could you explain more? I removed the part that may cause them not being able to move freely.

Code:

``````local hrp = script.Parent.HumanoidRootPart

if not hrp:FindFirstChild("LinearVelocity") then
local velocity = Instance.new("LinearVelocity")
velocity.Attachment0 = hrp.RootAttachment
velocity.VectorVelocity = Vector3.new(0, 5, 0)
velocity.Parent = hrp
end
``````

It now doesn’t make the player go upwards…

I just had to change VelocityConstraintMode from Vector to Line lol.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.