Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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.

0
Thanks again! TokumeiNo 15 — 9y
Ad

Answer this question