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

How to change the walking animation related to the direction?

Ill make it simple: I want to make the character play a certain walking animation when going forward and another when going backwards, this is what i've tried so far:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local Camera = workspace.CurrentCamera
local Result = Camera.CFrame:VectorToObjectSpace(Humanoid.MoveDirection)
while true do
wait(1)
print(Result) --This prints 0,0,0 every 1 second- Doesnt work.
end

Anything that helps me reach my goal would be appreciated, thanks.

3 comments

0

You might want to use lookvector or something. Might want to look up a tutorial, I'll be back soon with an update.

0

Okay, you actually might want to use UIS(UserInputService) search up a tutorial about UIS. This might help you.

0

The UserInputService worked, but with some glitches, i guess i can fix that with no problems,thanks!

1 answer

I would change the defaut walk animation everytime you press S (or your custom key).

local UIS = game:GetService("UserInputService")
local animateScript = character:WaitForChild("Animate")

-- Change the defaut walk animation:
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://CustomAnimationForwards"

-- Walk Backwards animation when pressing S:
UIS.InputBegan:Connect(function(key) 
	if key.KeyCode == Enum.KeyCode.S then
		animateScript.walk.WalkAnim.AnimationId = "rbxassetid://CustomAnimationBackWards"
		end
	end
end)

-- Reset Forward animation when release S:
UIS.InputEnded:Connect(function(key) 
	if key.KeyCode == Enum.KeyCode.S then
		animateScript.walk.WalkAnim.AnimationId = "rbxassetid://CustomAnimationForWards"
		end
	end
end)

1 comment

0

Maybe this code makes it have to load the assetId every time so it gets laggy, but you can do something in this way anyways, like just changing places with another animation object, so it keeps preloaded.

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