How do I simulate the player moving?

Basically I’m making a script where players can control another player with commands, like !w, !s for forward and backward.

So if a person says “!w” in chat I’d like the script to simulate the controlled player pressing the w key for about one second, with the walking animation and everything.

I know you could use Humanoid:MoveTo() to do this, but I’ve been struggling with finding the correct CFrames, getting lost in a mess of CFrame math and a bunch of stuff suffixed by vector (LookVector, ZVector, RightVector) and honestly I can’t figure it out. I just want to make it exactly simulate the player in question pressing a key.

I’d like it to behave as if the player had shift lock on so it doesn’t turn for moving places (I’ll add commands to implement turning later) and also as if the player’s camera was focused behind the player, so W would make it go forward etc.

Thanks!

Move this to #scripting-support

thank you, was making a tutorial and had the category selected when i made this pst

try Player:Move()

Takes a Vector3 and a bool that determines if it should move to the direction relative to the camera

here’s some code to make the character walk forward

local Player: Player = game.Players.ToldFable
local Char: Model = Player.Character or Player.CharacterAdded:Wait()
local Humanoid: Humanoid = Char:WaitForChild("Humanoid")
local RootPart: BasePart = Char:WaitForChild("HumanoidRootPart")

task.wait(5)

local forwardCFrame : CFrame = RootPart.CFrame*CFrame.new(0,0,-20)
Humanoid.WalkToPoint = forwardCFrame.Position

Well, I tried it but it only moved for a small splitsecond. I know I could loop it but I’m trying to get the commands to simulate moving for like a second, and I have no idea how long exactly Humanoid:Move runs for

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