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

Can someone give me a script that will run an animation on the MouseButton1Down Event?

If not, at least tell me what's wrong with my script.

script.Parent.MouseButton1Click:connect(function()
	local animation = Instance.new("Animation")
	animation.AnimationId = "http://www.roblox.com/Asset?ID=4147090414"
	local animTrack = Humanoid:LoadAnimation(animation)
	animTrack:Play()
end)

1 answer

✓ Accepted answer

This should be a localscript

Well, there's nothing in particular wrong with your code, other than on line 3 when you wrote 'Humanoid'. So this would error if you haven't defined Humanoid yet. Also, for efficiency, create the animation outside the scope of the MouseButton1Click event. If it's inside, then each time you click the gui a new Animation object will be created. And you might also want to load the animation onto the Humanoid outside the scope of the MouseButton1ClickEvent

So, revised.. but you still have to define 'Humanoid'

local Humanoid --Define this please.
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=4147090414"
local animTrack = Humanoid:LoadAnimation(animation)

script.Parent.MouseButton1Click:connect(function()
    animTrack:Play()
end)

If you have trouble defining the Humanoid then either PM me on the site or tell me on here where this script is located.

1 comment

0

Thanks again!

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