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
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
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.
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)