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

How to make a player move left/right for a keybind script?

Asked by 4 years ago

Hello, I know the question was a bit wonky but I have a script here where, if you double jump, you will fly until you double jump again. It can only go forward(keybind W) and backward(keybind S)

Here is the script of the movement.

01UIS.InputBegan:Connect(function(Input)
02    if Input.KeyCode == Enum.KeyCode.S then -- this is moving backward when you click S
03        if Toggle == false then return end
04        HumaoidRP.Anchored = false
05        if HumaoidRP:FindFirstChildOfClass("BodyVelocity") then
06            HumaoidRP:FindFirstChildOfClass("BodyVelocity"):Destroy()
07        end
08        local Back = Instance.new("BodyVelocity",HumaoidRP)
09        Back.Name = "BackMovement"
10        Back.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
11        local Gyro = Instance.new("BodyGyro",HumaoidRP)
12        Gyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
13        Gyro.D = 100
14        Gyro.P = 10000
15        while Toggle == true do
View all 33 lines...

My problem is, how can I make it go right/left? I know I need to change the .Velocity = Mouse.Hit.lookVector*-30, but not sure how. I know that it's all math but I'm very unsure. Does anyone know how to make the movement go right/left?

1 answer

Log in to vote
1
Answered by 4 years ago

So, how a body velocity works is it moves the character by how much you told it to, so here's how to move the player to the right, Change this line:

1Back.Velocity = Mouse.Hit.lookVector*Vector3.new(30,0,0)

To the right:

1Back.Velocity = Mouse.Hit.lookVector*Vector3.new(-30,0,0)

Hope it helps!

0
Ah it did work but it's moving on the x axis of the whole game, not the actual model for some reason, but thank you! Aprilsaurus 48 — 4y
0
hmm, do you have a weld? alexfinger21 341 — 4y
Ad

Answer this question