Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My animation won't work when I click a button?

I'm making a script where u click a button and it plays the animation. Something is wrong and here is the code:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local hum = char.Humanoid
local idle = hum:LoadAnimation(script.Animation)

script.Parent.MouseButton1Click:Connect(function()
	idle:Play()
end)

the system says there is something wrong with line 3 but I have no clue what it is

3 comments

0

and this is r15

0

is it a localscript?

0

yes

1 answer

try moving lines 2-4 to right before line 7, so they are inside the function. You are probably going to want to load the animation each time it is clicked so updated script :

local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	local char = plr.Character or plr.CharacterAdded:wait()
	local hum = char:WaitForChild("Humanoid")
	local idle = hum:LoadAnimation(script.Animation)
	idle:Play()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.