AnimationTrack is not stopping

Hello,

I have a module in my game that controls animations such as crawling. My issue here is that when I call :Stop() on the returned AnimationTrack, it’s not being stopped. I made sure that I’m not creating a new AnimationTrack when stopping, but my animation is still playing. I also made sure that crawlanim is not nil. Any ideas? Here’s my code:

Animation module:

function module:GetAnimation(plr, name, looped)
	if plr == nil then return false end
	if name == nil then return false end
	if anims[name] == nil then return false end
	if plr.Character == nil then return false end
	
	local hum = plr.Character:FindFirstChildOfClass("Humanoid")
	local newAnim = Instance.new("Animation")
	newAnim.AnimationId = util:RbxAsset(anims[name]) -- equivalent to rbxassetid://id
	
	local loadedAnim = hum:LoadAnimation(newAnim)
	loadedAnim.Looped = looped
	
	return loadedAnim
end

Crawling code:

local crawlanim = nil
local crawling = false

function handleCrawlAnim(hum, crawlanim)
	if crawling then
		if hum.MoveDirection.Magnitude > 0 then
			crawlanim:AdjustSpeed(0.5)
		else
			crawlanim:AdjustSpeed(0)
		end
	end
end

if not crawling then
		crawlanim = anim:GetAnimation(plr, "crawl")
		crawlanim:Play()
		hum.WalkSpeed = 3
		handleCrawlAnim(hum, crawlanim)
		hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
			handleCrawlAnim(hum, crawlanim)
		end)
		crawling = true
		return true
	else
		hum.WalkSpeed = 16
		if crawlanim ~= nil then
			crawlanim:Stop()
		end
		crawling = false
		return false
	end

Any ideas? Thanks,
pos0.

Nevermind, not solved. Amazing

Try putting a wait() before crawling = true

Just tried it, sadly it didn’t work.

Can you show the whole script?

Those are the only parts of the script that I think are needed to know this issue. I can add the handleCrawlAnim function to the crawling code, but that’s basically all that is needed.

Is this at the beginning of the script?

1 Like

Yes, this is at the beginning of the script.