How can i check if the humanoid of a player is playing an animation

the title is staight to the point

local function loadanimation(plr)

	local character = plr.Character

	character.Humanoid.WalkSpeed = 0
	character.Humanoid.JumpPower = 0
	local humanoid = character.Humanoid
if not humanoid:IsPlaying() then
	
		local animation = Instance.new('Animation')
		animation.AnimationId = 'rbxassetid://17209499163'
		local hum = character.Humanoid
		character.Humanoid.WalkSpeed = 0
		local anim =	hum:LoadAnimation(animation)
		anim:Play()
		repeat wait() until  anim.IsPlaying == false
		character.Humanoid.JumpPower = 50

		character.Humanoid.WalkSpeed = 16
end






end
prox.Triggered:Connect(function(plr)
	if db == false then
		db = true 
		plr.leaderstats.Poop.Value += 20
		arrow.Transparency = 1
		prox.Enabled = false
		loadanimation(plr)
		wait(waitime)
		prox.Enabled = true
		arrow.Transparency = 0
		db = false
	end
end)

I am surprised this doesnt work as i followed this [post] (Check if animation is playing)

I am assuming its not outdated as its only 1 year old

This is asking if a animation named humanoid is not playing. Your animation is called anim.

yes but i want to make it if an animation is already playing (as exemple from another script) then this one doesnt play

use :SetAttribute() and then check for that attribute in a different script

example:

--script 1
humanoid:SetAttribute("animationPlaying", true)
anim:Play()

anim.Ended:Wait() -- make sure to change it back after the animation is done
humanoid:SetAttribute("animationPlaying", false)

--script 2
if not humanoid:GetAttribute("animationPlaying") then
  anim:Play()
end

you can try getting the number of animation tracks playing on the humanoid’s animator and comparing it to 1. if the number of animations playing is less than 1, that means that no animation is playing, so your if-statement would look like this:
if not #humanoid.Animator:GetPlayingAnimationTracks() < 1 then

Edit: I realized a potential problem with this is that :GetPlayingAnimationTracks() is also going to count default roblox animations such as walking, idling, etc., but maybe :GetPlayingAnimationTracks() can be used to narrow down the problem somewhere. A solution you could try is having a function that runs through all the playing animations and doesn’t count animations with certain names inside of a table. If you wanted to do this, your code would look like this:

local exluded = {"Animation1, Animation2"} --put the names of the animations you want to exclude. Animation1 and Animation2 are the names of the default idle animations

function CanPlay(hum)
	for i, v in pairs(hum.Animator:GetPlayingAnimationTracks()) do
		if not table.find(exluded, v.Name) then --this means theres an animation that is not excluded playing
			return false
		end
	end
	return true
end

local function loadanimation(plr)

	local character = plr.Character

	character.Humanoid.WalkSpeed = 0
	character.Humanoid.JumpPower = 0
	local humanoid = character.Humanoid
	local playAnim = CanPlay(humanoid)
	
	if playAnim then

		local animation = Instance.new('Animation')
		animation.AnimationId = 'rbxassetid://17209499163'
		local hum = character.Humanoid
		character.Humanoid.WalkSpeed = 0
		local anim =	hum:LoadAnimation(animation)
		anim:Play()
		repeat wait() until  anim.IsPlaying == false
		character.Humanoid.JumpPower = 50

		character.Humanoid.WalkSpeed = 16
	end






end
prox.Triggered:Connect(function(plr)
	if db == false then
		db = true 
		plr.leaderstats.Poop.Value += 20
		arrow.Transparency = 1
		prox.Enabled = false
		loadanimation(plr)
		wait(waitime)
		prox.Enabled = true
		arrow.Transparency = 0
		db = false
	end
end)

Let me know if this helps :slight_smile:

This may just be a valid case for the script wide global, _G.