Animation GUI help

Hey developers!

I’m trying to create a GUI that has multiple different buttons that play multiple different animations, similar to TTD3 or Vibe NYC. Although, it seems that it’s not working as intended. No errors appear in the output, and since I’m not a very good programmer, I can’t figure out the problem myself. I’ve seen from other posts that animations can be a bit strange when programming, and now I see why.

What is wrong with this script?

-- local script

local p = script.Parent
local plr = game.Players.LocalPlayer

repeat wait() until plr.Character

local char = plr.Character
local humanoid = char:WaitForChild("Humanoid")
local animation

function playAnimation(id)
	if char ~= nil and humanoid ~= nil then
		local id = "rbxassetid://".. tostring(id)
		local oldAnimation = char:WaitForChild("LocalAnimation")
		if animation ~= nil then
			animation:Stop()
		end
		if oldAnimation ~= nil then
			if oldAnimation.AnimationId == id then
				oldAnimation:Destroy()
				return
			end
			oldAnimation:Destroy()
		end
		
		local newAnimation = Instance.new("Animation", char)
		newAnimation.Name = "LocalAnimation"
		newAnimation.AnimationId = id
		
		animation = humanoid:LoadAnimation(newAnimation)
		animation:Play()
	end
end

local BTN1 = p.BTN1

BTN1.MouseButton1Click:Connect(function()
	playAnimation(BTN1.AnimationID.Value)
end)

-- the animation id i'm using for BTN1 is "6985706275"

Thanks in advance!

1 Like

It doesn’t play because you didn’t include the animation ID in the variable ID.

Try setting the variable ID to the following:

"http://www.roblox.com/asset/id?=6985706275"
1 Like

You also kinda wrote the code a lot more complex than you needed to, there are many ways you could simplify that.

1 Like

Unfortunately, nothing changed.

I tried simplifying it, but it still doesn’t work. Now, that could be my scripting skills since I’m not very good, but here’s what I changed the script to in hopes that it’d work.

local p = script.Parent
local plr = game.Players.LocalPlayer

local char = plr.Character
local humanoid = char:WaitForChild("Humanoid")

local animation = Instance.new("Animation", char)
animation.Name = "Animation"

function playAnim1()
	if char ~= nil and humanoid ~= nil then
		local id = "rbxassetid://6985706275"
		
		animation.AnimationId = id
		local newAnimation = humanoid:LoadAnimation(animation)
		newAnimation:Play()
	end
end

local BTN1 = p.BTN1

BTN1.MouseButton1Click:Connect(function()
	playAnim1()
end)

Are there any visible problems? The only output from this script is the line that says “playAnim1()” in the click area, which leads me to think that there’s obviously something wrong with the main function.

Is your button’s .Active property true? The connection won’t be activated if the button isn’t Active.

Yes, I am really confused on this one.

Screen Shot 2021-08-04 at 11.55.12 AM

Is the animation yours? I don’t think you can play other people’s animations.

That may be the problem, my friend made it.

How would I make the animation mine? Is there a post about it anywhere?

Um, I’ve encountered the same issue. You can use a group game (team create doesn’t work) or you use assetdelivery.roblox.com/?id=

Try using Humanoid.Animator:LoadAnimation() instead of Humanoid:LoadAnimation()

That’s not true, as far as I know. I’ve been able to use animations made by other people. Humanoid:LoadAnimation() is deprecated. Read this post for more information.

How would I use assetdelivery? I’m interested as tat may be able to help me in other games as well.

This should be:
http://www.roblox.com/asset?id=6985706275

sorry my bad, my head isnt in the right place today

Can you let me know if the animations are under the experience’s owner? If the experience is owned by a group, the animation must be uploaded to the group that owns the experience. The same goes for experiences that are owned directly by your Roblox profile. If so, the animation must be uploaded and owned by you. Hope this helps. :grinning: