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
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
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)