Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i make player move forward when clicked on a button like R?

1 answer

✓ Accepted answer

In the example you used its obvious that you tried to use the character animations, I will tell you this now, this will NEVER work, animations will only move character parts/joints never the HumanoidRootPart (Which is where the camera is centered on). You can fix all this by using a body velocity. (Also make sure to have the animation not move the character or else it will do both movements at the same time). Makes sure this is all a local script.

local player = game:GetService("Players").LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local RootPart = Character.HumanoidRootPart
-- if you already have the variables above in your own script there is no need to write them again

--instead of using animations we will use a bodyvelocity, it is basically speed in a given direction

local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
--in order to make the character actually move, we will give them speed in the direction they are facing
BV.Velocity = RootPart.CFrame.lookVector.Unit * 50 -- you can change this if its too fast or too slow
--make sure it is parented to the "HumanoidRootPart" if it's not the script won't work.
BV.Parent = RootPart
wait(2) -- or however long you want the speed to last
BV:Destroy()

I hope this fixed your problem and please mark this as the answer if so! :)

6 comments

0

ill try rn thanks for helping

0

OMG IT WORKS

0

Hey dude it works but when i press the R button player playes the walking animation and prevents the slash animation to play if i make players walkspeed 0 can that help?

1

Yep, that will stop them from moving during the whole movement

0
1

make sure the animation is on "Action" priority if the animation isn't playing, looking at it the velocity and movement is obviously ok

This discussion is preserved as it was. New answers, comments, and votes are closed.