Struggling put together animations with a custom Animate script

I’m trying to put all these animation together and I’m not sure how to do that, I couldn’t find any helpful sources on the internet.

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local IdleAnimation = script:WaitForChild("Idle")
local IdleAnimationTrack = humanoid.Animator:LoadAnimation(IdleAnimation)

local RunAnimation = script:WaitForChild("Run")
local RunAnimationTrack = humanoid.Animator:loadAnimation(RunAnimation)
--the four lines of code above this comment are the ones I couldnt figure out how to put in.
--I'm also not sure how to activate the Idle animation when the player isnt moving.


local walkAnimation = script:WaitForChild("Walk")
local walkAnimationTrack = humanoid.Animator:loadAnimation(walkAnimation)


humanoid.Running:Connect(function(speed)
	if speed > 0 then
		if not walkAnimationTrack.IsPlaying then
			walkAnimationTrack:Play()
		end
	else
		if walkAnimationTrack.IsPlaying then
			walkAnimationTrack:Stop()
		end
	end
end)


-- I pasted this here in my script so I can kinda visually try and put it all in one function or something.
if not IdleAnimationTrack.IsPlaying then
	IdleAnimationTrack:Play()
end

Maybe I make a table?
I tried looking at the default Roblox Animate script but it wasn’t much help, Also I’m using a custom rig so the default Animate script is useless.

I’m currently not near my computer right now, but I think this might help you a bit?


local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local IdleAnimation = script:WaitForChild("Idle")
local IdleAnimationTrack = humanoid.Animator:LoadAnimation(IdleAnimation)

local RunAnimation = script:WaitForChild("Run")
local RunAnimationTrack = humanoid.Animator:loadAnimation(RunAnimation)

local walkAnimation = script:WaitForChild("Walk")
local walkAnimationTrack = humanoid.Animator:loadAnimation(walkAnimation)


humanoid.Running:Connect(function(speed)
	if speed > 0 then
		if not walkAnimationTrack.IsPlaying then
			walkAnimationTrack:Play()           
    IdleAnimationTrack:Stop()
		end
	else
		if walkAnimationTrack.IsPlaying then
			walkAnimationTrack:Stop()
     IdleAnimationTrack:Play()
		end
	end
end)

2 Likes

You can use HumanoidStateType for your situation
plus Player.Idled event

3 Likes

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