Improve and fix animation system

Does anyone know how i would change this animation module, its currently doesn’t work but I don’t think its a good system, how would I stop specific animations from playing and stop

local plr = game:GetService("Players").LocalPlayer
local chr = plr.Character
local animmodule = require(game:GetService("ReplicatedStorage").Modules.AnimationHandler)

chr:GetAttributeChangedSignal("WeaponEquipedAndHeld"):Connect(function()
	local weaponheld = chr:GetAttribute("WeaponEquipedAndHeld")
	if weaponheld == "" then
		animmodule.PauseAnimations(plr)
		animmodule.IdleAnim(plr,PlayerAnims)
	else
		animmodule.PauseAnimations(plr)
		animmodule.IdleAnim(plr,weaponheld)
	end
end)
local AnimsModule = {}
local replicatedfirst = game:GetService("ReplicatedFirst")
local animfolder = replicatedfirst:WaitForChild("Animations")


function AnimsModule.M1anim(player,WeaponName,CombatNum)
	print(player)
	print(WeaponName)
	print(CombatNum)
	local combatnum = Instance.new("StringValue")
	combatnum.Value = CombatNum
	combatnum.Name = "combatnum"
	
	
	for i,v in animfolder:GetChildren() do
		if v.Name == WeaponName then
			for i,s in v:GetChildren() do
				if s.Name == "M1" then
					print("M1 WORKS")
					for i,A in s:GetChildren() do
						if A.Name == combatnum.Value then
							print("IT RUN")
							local char = player.Character or player.CharacterAdded:Wait()
							local humanoid = char:FindFirstChildOfClass("Humanoid")
							local animtrack = humanoid:LoadAnimation(A)
							animtrack:Play()
						end
					end
				end
			end
		end
	end
end

function AnimsModule.IdleAnim(player,WeaponName)


	for i,v in animfolder:GetChildren() do
		if v.Name == WeaponName then
			for i,s in v:GetChildren() do
				if s.Name == "Idle" then
					local anim = s.Idle
					local char = player.Character or player.CharacterAdded:Wait()
					local humanoid = char:FindFirstChildOfClass("Humanoid")
					local animtrack = humanoid:LoadAnimation(anim)
					animtrack:Play()
					--animtrack.Looped = true
				end
			end
		end
	end
end

function AnimsModule.PauseAnimations(player,WeaponName)


	for i,v in animfolder:GetChildren() do
		for i,s in v:GetChildren() do
			for i,a in s:GetChildren() do
				for i,j in a:GetChildren() do
					j:Stop()
				end
			end
		end
	end
end



return AnimsModule

1 Like

The thing with animations is that you control them by telling their corresponding AnimationTrack to :Play() or :Stop(). Your AnimsModule.PauseAnimations() function is trying to call :Stop() on all the Animation objects located in ReplicatedFirst, not on the AnimationTracks that are playing.

To do what you’re trying to do, you’re going to need a way to store your AnimationTracks so that you can call :Stop() on them as you please. Unfortunately, you’re going to need to find a way to store AnimationTracks per player. It’s going to be tough, but you can do it!!

Also please use ReplicatedStorage instead of ReplicatedFirst, it’s not that scary I promise

1 Like

i will try to do that, thanks!
also i only put the animations in replicated first because i thought it would load the animations before being used lol

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