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

how to run animation on ClickDetector click?

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

5 comments

0

script please

0

just a sec

0

also, local scripts can access a click detector's mouse click event

0

it would be alot easier to read if you made it a lua chunk

0

Bruh this is from one year ago I figured this out already

2 answers

✓ Accepted answer

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

1 comment

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

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)

3 comments

0

(:connect) is Deprecated, you should use (:Connect).

0

Yup

0

the hit arguement of a click detector is the player who clicked it, not the part that touched it

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