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

This animation won't play online

script.Parent.ClickDetector.MouseClick:connect(function(playerWhoClicked)
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=147619125" -- your id here

local animTrack =script.Parent.Parent:FindFirstChild("Humanoid"):LoadAnimation(animation) 
-- change Humanoid to the target's Humanoid

animTrack:Play()

end)

It works in test mode but not in a server

2 comments

0

Could you please use prints to tell where the execution stops working ?

0

It doesn't execute at all.

2 answers

Unless you're loading in to a NPC ( not a character ) the wiki says it has to be a LocalScript.


--LocalScript in StarterGui or StarterPack

repeat wait() until game.Players.LocalPlayer

local PartName = "Part1" --Name of the part you want to click.
local animationId = "http://www.roblox.com/Asset?ID=147619125"
local p = game.Players.LocalPlayer
local mouse = p:GetMouse()

mouse.Button1Down:connect(function()
	if mouse.Target and mouse.Target.Name == PartName then
		local new = Instance.new("Animation")
		new.AnimationId = animationId
		p.Character.Humanoid:LoadAnimation(new):Play()
	end
end)

script.Parent.ClickDetector.MouseClick:connect(function(playerWhoClicked)
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=147619125" -- your id here

local animTrack =playerWhoClick.Character:FindFirstChild("Humanoid"):LoadAnimation(animation)
-- change Humanoid to the target's Humanoid

animTrack:Play()

end)

You aren't loading the animation on the script's parent, you want to find the character's humanoid so take the player value that the event returns and then find the character and it's humanoid then load the animation!

2 comments

1

Sorry that didn't make sense please explain?

0

doesn't work

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