Does the animation not load or does my script not work?

I made this emote menu script but its displaying an error and I’m not sure if its because of the animation or because of my script. I used emotes from the roblox marketplace.

Here is my script:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local frame = script.Parent.ScrollingFrame

local playing = false
local emote

for i, v in pairs(frame:GetChildren()) do
	if v:IsA("ImageButton") then
		v.MouseButton1Click:Connect(function()
			if playing == false then
				local hum = character:WaitForChild("Humanoid")
				emote = hum:LoadAnimation(v.Animation)
				hum.WalkSpeed = 0
				hum.JumpPower = 0
				emote:Play()
				playing = true
			elseif playing == true then
				local hum = character:WaitForChild("Humanoid")
				hum.WalkSpeed = 16
				hum.JumpPower = 50
				emote:Play()
				playing = false
			end
		end)
	end
end

The error code I’m getting is:

Failed to load animation - sanitized ID: rbxassetid://5917570207

Quick question, are you the owner of the place/game?

I already fixed this, but do you know why the animations aren’t as efficient as the actual ones?

This is the animation played via the UI


This is the one played using the “/e point” command

Try changing the animation priority to something high like ‘Action’. That way, the default Roblox animations hopefully wouldn’t interfere with your animation, causing to be less efficient.

It worked, but I converted the script into a local script and normal script controlled by remote emotes and now for some reason when its on the actual player’s screen it only does the animation 1 time, but when I switch to the server, it is looping and doesn’t stop looping. Every time I re-click the button, the animation gets faster but nobody can see the animations.

My LocalScript:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local frame = script.Parent.ScrollingFrame

local playing = false
local event = game.ReplicatedStorage.EmotesController
local debounce = false

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.EmotesMenu, false)

for i, v in pairs(frame:GetChildren()) do
	if v:IsA("ImageButton") then
		v.MouseButton1Click:Connect(function()
			if playing == false and debounce == false then
				debounce = true
				event:FireServer(v.Animation, "Play")
				playing = true
				wait(3)
				debounce = false
			elseif playing == true and debounce == false then
				debounce = true
				event:FireServer(v.Animation, "Stop")
				playing = false
				wait(3)
				debounce = false
			end
		end)
	end
end

My serverscript:

local event = game.ReplicatedStorage.EmotesController

event.OnServerEvent:Connect(function(player, anim, action)
	if action == "Play" then
		local char = player.Character
		local hum = char.Humanoid
		local emote = hum:LoadAnimation(anim)
		hum.WalkSpeed = 0
		hum.JumpPower = 0
		emote.Looped = true
		emote.Priority = Enum.AnimationPriority.Action
		emote:Play()
	elseif action == "Stop" then
		local char = player.Character
		local hum = char.Humanoid
		local emote = hum:LoadAnimation(anim)
		hum.WalkSpeed = 16
		hum.JumpPower = 50
		emote.Looped = false
		emote:Stop()
	end
end)

Try this code.

local event = game.ReplicatedStorage.EmotesController

event.OnServerEvent:Connect(function(player, anim, action)
	if action == "Play" then
		local char = player.Character
		local animator = char.Humanoid.Animator
		local emote = animator:LoadAnimation(anim)
		hum.WalkSpeed = 0
		hum.JumpPower = 0
		emote.Looped = true
		emote.Priority = Enum.AnimationPriority.Action
		emote:AdjustSpeed(1)
		emote:Play()
	elseif action == "Stop" then
		local char = player.Character
		local animator = char.Humanoid.Animator
		local emotes = animator:GetPlayingAnimationTracks()
		
		for i, emote in print(emotes) do
			if emote.Name == "EmoteName" then -- Change this "EmoteName" to your emote name
				emote.Looped = false
				emote:Stop()
			end
		end
		
		hum.WalkSpeed = 16
		hum.JumpPower = 50
	end
end)

“ServerScriptService.Script:21: attempt to iterate over a nil value”

Sorry, I messed up a little. Try this instead.

local event = game.ReplicatedStorage.EmotesController

event.OnServerEvent:Connect(function(player, anim, action)
	if action == "Play" then
		local char = player.Character
		local hum = char.Humanoid
		local emote = hum:LoadAnimation(anim)
		hum.WalkSpeed = 0
		hum.JumpPower = 0
		emote.Looped = true
		emote.Priority = Enum.AnimationPriority.Action
		emote:AdjustSpeed(1)
		emote:Play()
	elseif action == "Stop" then
		local char = player.Character
		local hum = char.Humanoid
		local emotes = hum:GetPlayingAnimationTracks()

		for i, emote in print(emotes) do
			if emote.Name == "EmoteName" then -- Change this "EmoteName" to your emote name
				emote.Looped = false
				emote:Stop()
			end
		end

		hum.WalkSpeed = 16
		hum.JumpPower = 50
	end
end)

Thanks it worked, I think the print was a typo because I changed it to pairs and it worked.

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