Animations not playing on Serverside, No errors

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am trying to make a custom animationHandler that plays animations from a folder.

  1. What is the issue? Include screenshots / videos if possible!
    The problem im currently experiencing is that the animations are playing for the NPCs, but not for player characters.

  2. What solutions have you tried so far? Did you look for solutions on the Creator Hub?

I have implemented checks for: Valid Animation ID, Existing Animator, Animation Track Priority.
I have re-uploaded all the animations with track priority and set the permissions properly.

Animation Handler:

local Debris = game:GetService(‘Debris’)
local Assets = game.ReplicatedStorage.Assets
local AnimationsFolder = Assets.Animations

local AnimationHandler = {}

AnimationHandler.__index = AnimationHandler

function AnimationHandler.new(CharacterModel)
local OB = {
Character = CharacterModel,
ItemAnimations = {},
}

setmetatable(OB, AnimationHandler)

return OB

end

function AnimationHandler:Init()
local Character = self.Character

self:OnCharacterAdded(Character)

--Load Animations
local AnimContextFolder = AnimationsFolder.Item

local function ForItemCategory(CategoryFolder)
	local CategoryName = CategoryFolder.Name
	local StuffInFolder = CategoryFolder:GetChildren()

	for _, Animation: Animation in pairs(StuffInFolder) do
		local ActionName = Animation.Name
		local AnimationName = CategoryName..ActionName --MeleeSwing, ToolEquip, StaffAttack

		self.ItemAnimations[AnimationName] = Animation
	end
end

for _, CategoryFolder in pairs(AnimContextFolder:GetChildren()) do
	ForItemCategory(CategoryFolder)
end

end

function AnimationHandler:OnCharacterAdded(Character)
local Humanoid: Humanoid = Character:WaitForChild(‘Humanoid’)

self.Character = Character

local Animator = Humanoid:WaitForChild('Animator')


if not Animator then
	print('bah')
	--Animator = Instance.new('Animator', Humanoid)
end

self.Animator = Animator

end

function AnimationHandler:PlayAnimation(AnimationObject: Animation, specificTime: number)
local Animator: Animator = self.Animator

if not Animator then
	print('Invalid animator for: ', self.Character)
end

local ID = AnimationObject.AnimationId; 

if (ID == '') or (string.len(ID) == 0) then 
	--print('Animation has no ID: ', AnimationObject, ' Character: ', self.Character) 
	return 
end

local Track: AnimationTrack = Animator:LoadAnimation(AnimationObject); Track.Priority = Enum.AnimationPriority.Action2

if specificTime then
	local AnimationDefaultSpeed = Track.Length
	Track:AdjustSpeed(specificTime/AnimationDefaultSpeed)
	print('adjusting animatoin spead')
end

print('ANIMATION TRACLK: ', Track)

game.ReplicatedStorage.PlayPlayerAnimation:FireAllClients(self.Character, AnimationObject)

task.wait()

Track:Play()

--Debris:AddItem(Track, Track.Length)

end

function AnimationHandler:PlayLoadedAnimation(ActionName)
local AnimationObject = self.ItemAnimations[ActionName]; if not AnimationObject then error(‘[AnimationHandler]: Animation Does not exist:’..ActionName) return end

self:PlayAnimation(AnimationObject)

end

return AnimationHandler

1 Like

Could you please wrap them in these ``` it would make it so easy to read your code. Also it’s kinda hard to get what you mean when you say “animations not playing on the serverside, no errors” and the other bit of info we get is that you said “The problem im currently experiencing is that the animations are playing for the NPCs, but not for player characters.”

So my guess for your error is you are playing the animations on the client (which you should do) and you want to see it on the server. Is there really a need for the animations to be seen on the server? Because your only going to usually see your client.

1 Like

Agreed. Most people (including me) won’t even attempt to solve your problem if the code isn’t formatted.

Valid point. Perhaps he is referring to animation replication.

formatted for you helpers

local Debris = game:GetService(‘Debris’)
local Assets = game.ReplicatedStorage.Assets
local AnimationsFolder = Assets.Animations

local AnimationHandler = {}

AnimationHandler.__index = AnimationHandler

function AnimationHandler.new(CharacterModel)
	local OB = {
		Character = CharacterModel,
		ItemAnimations = {},
	}

	setmetatable(OB, AnimationHandler)

	return OB
end

function AnimationHandler:Init()
	local Character = self.Character

	self:OnCharacterAdded(Character)

	--Load Animations
	local AnimContextFolder = AnimationsFolder.Item

	local function ForItemCategory(CategoryFolder)
		local CategoryName = CategoryFolder.Name
		local StuffInFolder = CategoryFolder:GetChildren()

		for _, Animation: Animation in pairs(StuffInFolder) do
			local ActionName = Animation.Name
			local AnimationName = CategoryName..ActionName --MeleeSwing, ToolEquip, StaffAttack

			self.ItemAnimations[AnimationName] = Animation
		end
	end

	for _, CategoryFolder in pairs(AnimContextFolder:GetChildren()) do
		ForItemCategory(CategoryFolder)
	end
end

function AnimationHandler:OnCharacterAdded(Character)
	local Humanoid: Humanoid = Character:WaitForChild(‘Humanoid’)

	self.Character = Character

	local Animator = Humanoid:WaitForChild('Animator')


	if not Animator then
		print('bah')
		--Animator = Instance.new('Animator', Humanoid)
	end

	self.Animator = Animator
end

function AnimationHandler:PlayAnimation(AnimationObject: Animation, specificTime: number)
	local Animator: Animator = self.Animator

	if not Animator then
		print('Invalid animator for: ', self.Character)
	end

	local ID = AnimationObject.AnimationId; 

	if (ID == '') or (string.len(ID) == 0) then 
		--print('Animation has no ID: ', AnimationObject, ' Character: ', self.Character) 
		return 
	end

	local Track: AnimationTrack = Animator:LoadAnimation(AnimationObject); Track.Priority = Enum.AnimationPriority.Action2

	if specificTime then
		local AnimationDefaultSpeed = Track.Length
		Track:AdjustSpeed(specificTime/AnimationDefaultSpeed)
		print('adjusting animatoin spead')
	end

	print('ANIMATION TRACLK: ', Track)

	game.ReplicatedStorage.PlayPlayerAnimation:FireAllClients(self.Character, AnimationObject)

	task.wait()

	Track:Play()

	--Debris:AddItem(Track, Track.Length)
end

function AnimationHandler:PlayLoadedAnimation(ActionName)
	local AnimationObject = self.ItemAnimations[ActionName]; if not AnimationObject then error(‘[AnimationHandler]: Animation Does not exist:’..ActionName) return end

	self:PlayAnimation(AnimationObject)
end

return AnimationHandler
1 Like

Twank you gwood swir!