Module Script Not Stopping animation

You simply use ``` at both the starting and the end of your code.

Like this:
-- ```
print("Hello World!")
-- ```
Within your text.
1 Like

Here’s what I have so far:

local Abilities = {}

local Status = "normal"

local Animations = script.Animations
local Sounds = script.Sounds

Abilities.SawHand = function(Character, play)
	local Humanoid = Character:WaitForChild("Humanoid")
	local Animator = Humanoid:WaitForChild("Animator") -- if it's a custom character, maybe you'd want to place the Animator inside the humanoid.

	local SawAnim = nil

	for _, track in Animator:GetPlayingAnimationTracks() :: { AnimationTrack } do
		local _Animation = track.Animation
		local _animId = _Animation.AnimationId

		if _animId == Animations.SawHand.AnimationId then
			SawAnim = track
			break
		end
	end
	
	SawAnim.Looped = true
	
	local SawHandSound = Sounds.SawHand
	SawHandSound.Looped = true
	
	if Character:WaitForChild("RightHand"):FindFirstChild("SawHand") then
		SawHandSound = Character:WaitForChild("RightHand"):FindFirstChild("SawHand")
	else
		SawHandSound = Sounds:WaitForChild("SawHand"):Clone()
		SawHandSound.Parent = Character:WaitForChild("RightHand")
	end
	
	
	if play then
		SawAnim:Play()
		SawHandSound:Play()
	else
		SawAnim:Stop()
		SawHandSound:Stop()		
	end
end

return Abilities

Im getting an error “Line 24, attempt to index nil with ‘Looped’”

Ahh, I forgot to add another piece of code to account if there’s no playing SawHand animation.

Just add this after the loop

if not SawAnim then -- if there's no animation with the Animations.SawHand id, since it'll stay nil if no id was found...
    SawAnim = Animator:LoadAnimation(Animations.SawHand)
end

Now, theoretically, everything should be working dandy for you. Let us know if there’s any other inconveniences that occur.

Works Perfectly!!! Thank you so much for spending a whole hour to help me I really appreciate it!

Here’s a link to the game if you have nothing else to do: Flash - Roblox

1 Like

Oh yeah, one question for the road, how do I get badges such as the “animation” one you have?

You’re welcome! I’ll play it whenever I get the chance to, and I do wish you a good luck on your game development!

If you want to, you can PM me about the game for other things I could help you with, or just to keep me updated of its development. It seems from your code it’ll look amazing!

To not have this post be spammed with us talking, I’ll PM you about that.

1 Like

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