Animations Script Not Working

I am trying to create emote gui. I want a list of emotes that when players select one it will loop an emote.

However it does not seem to be working. Whenever I test the game the gui loads in fine but when I go to select an emote it does not play. No errors appear in the output when I play test the game. And before you ask, yes I did put animation id’s for each emote. I do not own the emotes that I am using but I do not believe that’s the reason why they are not loading.

Here are the elements of the gui

image

(I have not customized the gui so here is what it looks like for now)
image

Here is the local script:


local templplateBtn = script:WaitForChild("AnimButton")

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")


local currentAnim = nil

for i, anim in pairs(anims) do
	
	local loadedAnim = humanoid:LoadAnimation(anim)
	loadedAnim.Looped = true
	loadedAnim.Priority = Enum.AnimationPriority.Action
	
	local templateClone = templplateBtn:Clone()
	templateClone.Text = anim.Name
	
	templateClone.Parent = script.Parent.AnimationScroll
	
	
	templateClone.MouseButton1Click:Connect(function()
		
		if currentAnim ~= loadedAnim then
			
			if currentAnim then currentAnim:Stop() end
			
			currentAnim = loadedAnim
			currentAnim:Play()
			
		elseif currentAnim == loadedAnim then
			
			currentAnim:Stop()
			currentAnim = nil
		end
	end)
end

I can’t seem to find the bug. If someone could help me that would be appreciated. :smiley:

Thank You!

(Also if it is a silly mistake, I am sorry. I am new to scripting.)

Are you meaning to run the mouseclick function within the iv pairs? If not try:

local templplateBtn = script:WaitForChild("AnimButton")

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")


local currentAnim = nil

for i, anim in pairs(anims) do
	
	local loadedAnim = humanoid:LoadAnimation(anim)
	loadedAnim.Looped = true
	loadedAnim.Priority = Enum.AnimationPriority.Action
	
	local templateClone = templplateBtn:Clone()
	templateClone.Text = anim.Name
	
	templateClone.Parent = script.Parent.AnimationScroll
	
end	
	templateClone.MouseButton1Click:Connect(function()
		
		if currentAnim ~= loadedAnim then
			
			if currentAnim then currentAnim:Stop() end
			
			currentAnim = loadedAnim
			currentAnim:Play()
			
		elseif currentAnim == loadedAnim then
			
			currentAnim:Stop()
			currentAnim = nil
		end
	end)

[/quote]