Animation not playing

Hello,

I do not know why but only one animation is playing on my character…

Script when I spawn with my character:

local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.UI.MainMenu.Deploy

event.OnServerEvent:Connect(function(plr)
	local char = plr.Character
	
	local newCharacter = game:GetService("ReplicatedFirst")["Character Manager"].Character:Clone()

	newCharacter.Name = plr.Name
	plr.Character = newCharacter
	char:Destroy()
	char = plr.Character
	newCharacter.Parent = workspace
	
	char:MoveTo(workspace.PositionCharacter.Position)
	
	local newAnimate = game:GetService("ReplicatedFirst")["Character Manager"].Animate:Clone()
	newAnimate.Parent = char
end)

Animate script (it’s a localscript):

local rf = game:GetService("ReplicatedFirst")
local RS = game:GetService("RunService")
local plr = game:GetService("Players").LocalPlayer
local character = script.Parent

local humanoid = character:FindFirstChild("Humanoid")

repeat task.wait() until humanoid

local walkAnim = rf["Character Manager"].Walk
local pauseAnim = rf["Character Manager"].Pause
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
local pauseAnimTrack = humanoid.Animator:LoadAnimation(pauseAnim)

humanoid.Running:Connect(function(speed)
	if speed > 0 and speed < 17 then
		if pauseAnimTrack.IsPlaying then
			pauseAnimTrack:Stop()
		end

		if not walkAnimTrack.IsPlaying then
			walkAnimTrack:Play()
		end
	else
		if walkAnimTrack.IsPlaying then
			walkAnimTrack:Stop()
		end

		if not pauseAnimTrack.IsPlaying then
			pauseAnimTrack:Play()
		end
	end
end)

Videos:
https://gyazo.com/baec7a10e9e3b6b9e7427a4a1bd335ab
https://gyazo.com/9ffdfa6afca362502bcf1d4b398c6b67
https://gyazo.com/0bc994b57111d0e927fc8210fe2a0212

You can use GetPropertyChangedSignal to detect when the humanoid’s MoveDirection changes.

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

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
    if Humanoid.MoveDirection.Magnitude > 0 then
       -- Runs when the player is moving   
    elseif Humanoid.MoveDirection.Magnitude == 0 then
       -- Runs when player is not moving
    end
end)
1 Like

I have an idea but if I change the walkspeed of the character how can I check his speed, to play an animation for example when the player crouch or sprint.

Your thing is a solution :).

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