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

How to make animation play on left mouse click?

I have an animation that is for a tool I have created, the animation functions properly and I have it working with key presses thanks to devforums, except I can't seem to understand how to get it to properly sync up with the firing of the tool, and I haven't been able to grasp the wikis. I'd appreciate any explanation of what/why to change.

I have two separate localscripts one for directing the animation, and one for the tool itself.

Animation script:

local plr = game.Players.LocalPlayer
local char = plr.Character

local animQ = Instance.new("Animation")
animQ.AnimationId = "rbxassetid://1912586107"

game:GetService("UserInputService").InputBegan:connect(function(key,typ)
	if not typ then
		if key.KeyCode == Enum.KeyCode.Q then
			local track = char.Humanoid:LoadAnimation(animQ)
			track:Play()
		end
	end
end)

2 answers

✓ Accepted answer
local plr = game.Players.LocalPlayer
local char = plr.Character

local animQ = Instance.new("Animation")
animQ.AnimationId = "rbxassetid://1912586107"

game:GetService("UserInputService").InputBegan:connect(function(click,typ)
    if not typ then
        if click.UserInputType == Enum.UserInputType.MouseButton1 then
            local track = char.Humanoid:LoadAnimation(animQ)
            track:Play()
        end
    end
end)

2 comments

0

I appreciate the explanation very much, I really wasn't having any luck finding that I needed to change them to click.

0

the parameter does not matter, you just need UserInputType

To what I understand, the request is to make the tool, when equipped and clicked, make your humanoid play an animation?

If this is correct, use the Activated event of tool.

tool.Activated:Connect(function()
	 local track = char.Humanoid:LoadAnimation(animQ)
         track:Play()
end)

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