How to change a rig's animation depending on the movement direction of the player

I’m trying to make a JoJo game. Similar to Your Bizarre Adventure on roblox. And what I’m trying to do is whenever the player moves to a specific direction, then a corresponding animation plays for the rig.

So I know that I have to make a remote event to detect where the player is moving, but when the rig’s animation changes once, it doesn’t return to Idle.

I have made a script which when the “Q” button is pressed, then the player summons the rig and a summon animation plays and I think it’s one of the reason the other animations are interupted.

Nothing on the devforum helped for my problem

Local script

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if math.round(Humanoid.MoveDirection.X) == -1 then
		game:GetService("ReplicatedStorage"):WaitForChild("StandMovement"):FireServer("MovingLeft")
	elseif math.round(Humanoid.MoveDirection.X) == 1 then
		game:GetService("ReplicatedStorage"):WaitForChild("StandMovement"):FireServer("MovingRight")
	elseif math.round(Humanoid.MoveDirection.Z) == -1 then
		game:GetService("ReplicatedStorage"):WaitForChild("StandMovement"):FireServer("MovingForward")
	elseif math.round(Humanoid.MoveDirection.Z) == 1 then
		game:GetService("ReplicatedStorage"):WaitForChild("StandMovement"):FireServer("MovingBackward")
	elseif Humanoid.MoveDirection == 0 then
		game:GetService("ReplicatedStorage"):WaitForChild("StandMovement"):FireServer("Idle")
	end
end)


Server Script

game:GetService("ReplicatedStorage"):WaitForChild("StandMovement").OnServerEvent:Connect(function(player, state)
	local character = workspace:WaitForChild(player.Name)
	local stand = character:WaitForChild("TheWorld")
	local Idle = stand.AnimationController:LoadAnimation(stand.Idle)
	local Backward = stand.AnimationController:LoadAnimation(stand.MovingBackward)
	local summon = stand.AnimationController:LoadAnimation(stand.Summon)
	if state == "Idle" then
		Idle.AnimationPriority = Enum.AnimationPriority.Idle
			Idle:Play(0.00001)
			
	elseif state == "MovingBackward" then
		Backward:Play(0.00001)
	end
end)	

I don’t think i understand the problem
but replace math.round for math.roof, if the number you round is lesser than .5 it will round to 0,
also you don’t need to make the MoveDirection == 0 else does the same because every other statement has to be false for else to run

1 Like

I tried this but it doesnt work

	if state == "Backward" then
		Backward:Play()
		print("Backward")
		else
		Backward:Stop()
		print(Idle)
		Idle:Play()
	end

By the way I’m only working with the backwards animation because I haven’t made any other animation yet

By the way I tried what you said with the math.roof, but in the end it still didn’t work the way I wanted so I just switched to user input service.