ROBLOX, why is my character walking in place?
Anonymous in /c/coding_help
479
report
This is a ROBLOX question, I know I know but I'm desperate here, I have the following code inside a local script:<br><br>```lua<br>local player = game.Players.LocalPlayer<br><br>local character = player.Character<br><br>local MovementKeys = Enum.KeyCode<br>local RightKey = MovementKeys.D<br>local LeftKey = MovementKeys.A<br>local UpKey = MovementKeys.W<br>local DownKey = MovementKeys.S<br><br>local RightPressed = false<br>local LeftPressed = false<br>local UpPressed = false<br>local DownPressed = false<br><br>local KeyPressed = function()<br> if RightPressed then<br> RightPressed = false<br> end<br><br> if LeftPressed then<br> LeftPressed = false<br> end<br><br> if UpPressed then<br> UpPressed = false<br> end<br><br> if DownPressed then<br> DownPressed = false<br> end<br>end<br><br>if player.Character then<br> --Main movement function<br> while (true) do<br> wait()<br> if RightPressed then<br> character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(1, 0, 0)<br> end<br><br> if LeftPressed then<br> character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(-1, 0, 0)<br> end<br><br> if UpPressed then<br> character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0, 0, 1)<br> end<br><br> if DownPressed then<br> character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -1)<br> end<br> end<br>end<br>game:GetService("UserInputService").InputBegan:Connect(function(input)<br> local KeyPressed = function()<br> if RightPressed then<br> RightPressed = false<br> end<br><br> if LeftPressed then<br> LeftPressed = false<br> end<br><br> if UpPressed then<br> UpPressed = false<br> end<br><br> if DownPressed then<br> DownPressed = false<br> end<br> end<br><br> if input.KeyCode == RightKey then<br> RightPressed = true<br> end<br><br> if input.KeyCode == LeftKey then<br> LeftPressed = true<br> end<br><br> if input.Code == UpKey then<br> UpPressed = true<br> end<br><br> if input.KeyCode == DownKey then<br> DownPressed = true<br> end<br>end)<br><br>game:GetService("UserInputService").InputEnded:Connect(function(input)<br> local KeyPressed = function()<br> if RightPressed then<br> RightPressed = false<br> end<br><br> if LeftPressed then<br> LeftPressed = false<br> end<br><br> if UpPressed then<br> UpPressed = false<br> end<br><br> if DownPressed then<br> DownPressed = false<br> end<br> end<br><br> if input.KeyCode == RightKey then<br> RightPressed = false<br> end<br><br> if input.KeyCode == LeftKey then<br> LeftPressed = false<br> end<br><br> if input.KeyCode == UpKey then<br> UpPressed = false<br> end<br><br> if input.KeyCode == DownKey then<br> DownPressed = false<br> end<br>end)<br>```<br>When I press any of the keys, the character just moves in place, what do I mean? By this I mean that for example, when you press W, you'll see your character move a bit but it'll immediately snap back to the same position in which it was before you pressed the key, I don't know why this is happening, I've tried multiple things including setting the movement speed of the Humanoid itself and setting the animation speed of the walk animation but that didn't work either.
Comments (11) 19105 👁️