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

Click detectors with animation, can someone help?

Asked by 8 years ago

I want to make a click detector that activates an animation, but I don't know the code for it. Could I get some help?

1 answer

Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

You know you are going to need two Roblox Objects for this. Let's look them up on the wiki:

http://wiki.roblox.com/index.php?title=API:Class/ClickDetector http://wiki.roblox.com/index.php?title=Animations http://wiki.roblox.com/index.php?title=API:Class/Humanoid/LoadAnimation <-- There are actually 2 or 3 LoadAnimation functions.

Let's grab some sample code and work out what it does:

local part = Instance.new("Part", workspace) -- Create a new part in Workspace
local clickDetector = Instance.new("ClickDetector", part) -- Create a ClickDetector in Part

clickDetector.MouseClick:connect(function(player)
    -- Fire when someone clicks ClickDetector
    part.BrickColor = BrickColor.random()
end)
local animController = Instance.new("AnimationController") -- Create Animation Element
local animTrack = animController:LoadAnimation(animation) -- Preload Animation
animTrack:Play() -- Activate Animation
-- This is the one we use for Humanoids (at least, easier)
example = Humanoid:LoadAnimation(script.Parent.AnAnimation)
example:Play()

Now let's try combining these scripts to do the following:

Create a new part in Workspace Create a ClickDetector in Part

Create an animation element Preload Animation

When Someone Clicks:
    Find Which Player Clicked
        Play Animation for that Player
local part = Instance.new("Part", workspace) -- Create a new part in Workspace
local clickDetector = Instance.new("ClickDetector", part) -- Create a ClickDetector in Part
local animController = Instance.new("AnimationController") -- Create Animation Element
animController.AnimationId = "http://www.roblox.com/Asset?ID=144911345"

clickDetector.MouseClick:connect(function(player)
    -- Fire when someone clicks ClickDetector
    local example = Humanoid:LoadAnimation(animController)
    example:Play()
end)

See here for more example code. Hope everything works out for you! Be sure to hit Accept Answer if you I sufficiently answered your question, and leave a comment if you need further help!

0
Oh dude, this his awesome! I like the example as well <3 crystalclay 70 — 6y
Ad

Answer this question