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

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

Asked by 4 years ago

Ok so i want to click lets say R button on the keyboard and then player moves forward slowly

like this https://gyazo.com/f7f6bfef5a6fe329116befe4556fa7cf

Right now

https://gyazo.com/41bfd611c169c20e8c54168bc1adf427

i just used animation but camera stays in place and player comes back after its finished.

help :)

1 answer

Log in to vote
1
Answered by
Glacitron 239 Moderation Voter
4 years ago
Edited 4 years ago

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! :)

0
ill try rn thanks for helping themaxogamer 58 — 4y
0
OMG IT WORKS themaxogamer 58 — 4y
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? themaxogamer 58 — 4y
1
Yep, that will stop them from moving during the whole movement Glacitron 239 — 4y
View all comments (2 more)
0
hey dude https://gyazo.com/8807c49bfec7a54661dc1b16184ac809 it still doesnt work themaxogamer 58 — 4y
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 Glacitron 239 — 4y
Ad

Answer this question