animationtrack:Play() not working

I’m trying to make an emote system and have fixed all bugs except for the server-sided emote system. It’s placed within a gui that the player can pull out and use emotes at any time. Here’s the code:

local anim

script.Parent.taunt.OnServerEvent:Connect(function(plr,id,char,humanoid)
	
	if char ~= nil and humanoid ~= nil then
		
		--id = "rbxassetid://"..tostring(id)
		local oldanim = char:FindFirstChild("LocalAnimation")
		
		if anim ~= nil then
			anim:Stop()
		end
		
		if oldanim ~= nil then
			if oldanim.AnimationId == id then
				oldanim:Destroy()
				return
			end
			oldanim:Destroy()
		end

		local animation = Instance.new("Animation",char)
		animation.Name = "LocalAnimation"
		animation.AnimationId = id
		
		anim = humanoid.Animator:LoadAnimation(animation)
		anim:Play()
		
	end
	
end)

Everything is working fine, it’s just that anim:Play() isn’t doing anything when fired, and isn’t returning any errors

1 Like

im pretty sure it only works on local scripts.

but then how do i get the animation to show globally, or does it automatically do that?

Yeah animations load in local scripts everyone can see them

Just make sure the animation loading happens in starterplayerscripts.

1 Like

it still seems to not work, i pasted the code in and binded it to a bindableevent in replicatedstorage

So the localscript loads a animation upon pressing a button in a gui?

so the localscript fires a bindableevent in replicatedstorage which goes to a localscript in starterplayerscripts that loads the animation onto the target player and plays it

BindableEvents don’t work between different LocalScripts or between LocalScripts and the server unless they share the same execution context

*this is new for me i just looked it up.

it is firing, i tried printing once it received the event and it did, the problem is the animationtrack still isn’t playing

Well this is new for me, im afraid i can’t help you more. I’m new to coding i am using everything i know. But i don’t see the issue. My apologies

1 Like

From this other post try to load the animation only once in a local variable instead of everytime the function is ran.

Also if its an instance use wait for child(not in your case for animation id).

Im guessing its due to lag because roblox has to load the animation from the server which takes time, so you should only load the animation once.

1 Like

there are many different animations, so i have to load each one in order to be able to play the different ones

You can use a table to hold all the different animation according to index and also preload them so they play immediately when the function is ran.

1 Like

but how do i preload them if the contents are going to change each time the player buys a new emote?

Then you dont, just load the animation upon purchase.

However only do it once and then store it in memory (variable or table), not everytime you play it or else you will keep loading the same animation and hit the 256 animation limit I believe from my memory.

are you sure you’re not playing an R6 animation on R15 character or vise versa?

no, ive checked they’re both r6

roblox studio isn’t telling me that i’ve hit the 256 animation limit, as i added a debounce to the script that detects the button pressing

dont spread misinformation please

idk maybe ??

For me the fix was the add the debounce preloaded Here is an example:

local storedAnimations = {}

script.Parent.taunt.OnServerEvent:Connect(function(plr,id,char,humanoid)
	
	if char ~= nil and humanoid ~= nil then
		
		--id = "rbxassetid://"..tostring(id)
		local oldanim = char:FindFirstChild("LocalAnimation")
		
		if anim ~= nil then
			anim:Stop()
		end
		
		if oldanim ~= nil then
			if oldanim.AnimationId == id then
				oldanim:Destroy()
				return
			end
			oldanim:Destroy()
		end

		local animation = Instance.new("Animation",char)
		animation.Name = "LocalAnimation"
		animation.AnimationId = id
		
        local loadedAnimation = humanoid.Animator:LoadAnimation(animation)

		storedAnimations[plr] = {
           animation = loadedAnimation,
	end
	
      storedAnimations[plr].animation:Play()

end)