Is there any way to check if a character is idle

Hello, I have been trying to animate my bot but I cannot get the idle animation to work, here is the code I am using, but I don’t know why it keeps walking instead of staying idle

local Humanoid = script.Parent:WaitForChild(“Humanoid”)

Humanoid.StateChanged:Connect(function()
	local State = Humanoid:GetState()
	if State == Enum.HumanoidStateType.Running then
		local LA = Humanoid:LoadAnimation(script:WaitForChild("Walk"))
		LA:Play()
	elseif State == Enum.HumanoidStateType.Seated then
		local LA = Humanoid:LoadAnimation(script:WaitForChild("Sit"))
		LA:Play()
	elseif State == Enum.HumanoidStateType.Jumping then
		local LA = Humanoid:LoadAnimation(script:WaitForChild("Jump"))
		LA:Play()
	elseif Humanoid.MoveDirection == Vector3.new(0, 0, 0) and State ~= Enum.HumanoidStateType.Jumping and State ~= Enum.HumanoidStateType.Freefall then
		local LA = Humanoid:LoadAnimation(script:WaitForChild("Idle"))
		LA:Play()
	end
end)

Does anyone know why this is happening?

1 Like

I think you can put those events separately

Humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Running then
		local LA = Humanoid:LoadAnimation(script:WaitForChild("Walk"))
		LA:Play()
	elseif new == Enum.HumanoidStateType.Seated then
		local LA = Humanoid:LoadAnimation(script:WaitForChild("Sit"))
		LA:Play()
	elseif new == Enum.HumanoidStateType.Jumping then
		local LA = Humanoid:LoadAnimation(script:WaitForChild("Jump"))
		LA:Play()
	end
end)

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	local State = Humanoid:GetState()
	local direction = Humanoid.MoveDirection
	
	if direction == Vector3.new() and State ~= Enum.HumanoidStateType.Jumping and State ~= Enum.HumanoidStateType.Freefall then
		local LA = Humanoid:LoadAnimation(script:WaitForChild("Idle"))
		LA:Play()
	end
end)

Also, can’t you just fork the Animate script and convert it to a regular script and put it in the Bot and just change the ids around?

No, sadly this didn’t work, I cannot find what makes it to play the walk animation instead of the idle one

Are you able to fork the Animate script your player gets when you spawn in, copy it, paste it in the Bot and convert it to a regular script? Since from what I see, it’s quite similar to what you’re trying to do with custom animations

2 Likes

Thanks, this works, it gives some error, because the character isn’t attached to any player but I can fix them

1 Like

Anytime! if you have anymore issues don’t be afraid to make another post!

2 Likes