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

how to run animation on ClickDetector click?

Asked by 5 years ago
Edited 5 years ago

So im working on it for a long time now and i just cant make it work, i really need help. so from what i got u cant run animation on click detector or atleast it has to be a Local script... anyways... i did make a script a normal script and the only thing it does is run the animation on click but its only working on roblox studio...

so i just wanned to ask if someone knows how to run an animation on click of a click detector (please help me im working on it for too long and it wont work)

function onClicked() hum = game.Players.LocalPlayer.Character.Humanoid anim_feet = hum:LoadAnimation(script.Parent.Animation) current = anim_feet current:Play() wait(2.5) current:Stop() end script.Parent.ClickDetector.MouseClick:connect(onClicked)

that's a normal scripts and it only works in roblox studio

0
script please User#23365 30 — 5y
0
just a sec chacha489 16 — 5y
0
also, local scripts can access a click detector's mouse click event theking48989987 2147 — 5y
0
it would be alot easier to read if you made it a lua chunk ScriptsALot 91 — 4y
0
Bruh this is from one year ago I figured this out already chacha489 16 — 4y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Since animations can be played back on the client and be replicated to the server, and the client can access a click detector's input events, there isn't a solid reason to use a server script. So you can ditch the server script and just use a local script

--this should be a local script
local plr = game.Players.LocalPlayer

function click (plrClick)
    if plrClick and plr then
        if plrClick == plr then
            hum = plr.Character:FindFirstChild("Humanoid")
            if hum then 
                anim_feet = hum:LoadAnimation(workspace.Part.Animation)--or wherever your animation is located 
                current = anim_feet-- i don't see why this is necessary  
                current:Play() 
                wait(2.5)
                current:Stop()
            end
        end
    end
end
workspace.Part.ClickDetector.MouseClick:Connect(click)

this should be a local script in (preferrably) starter character scripts, this establishes the local player, then when the click detector is clicked, it checks if the player who clicked the thing is the local player, then if it is,it checks if there is a humanoid, if som then it plays the animation

And if there is anything wrong with this, just let me know

0
Dude im like trying to do thid for half a year now and u actually like make me cry rn thank you so much i appreciate man chacha489 16 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

You can't use the variable LocalPlayer in a normal script.

heres the fixed script:

function onClicked(hit) 
if hit.Parent:FindFirstChild("Humanoid") then
plr = game.Players:GetPlayerFromCharacter(hit.Parent)
hum = plr.Character.Humanoid 
anim_feet = hum:LoadAnimation(script.Parent.Animation) 
current = anim_feet 
current:Play() 
wait(2.5)
 current:Stop() 
end 
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
(:connect) is Deprecated, you should use (:Connect). AIphanium 124 — 5y
0
Yup mixgingengerina10 223 — 5y
0
the hit arguement of a click detector is the player who clicked it, not the part that touched it theking48989987 2147 — 5y

Answer this question