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

How to play animation when clicked with a tool?

I did it like this but it just won't work. Please help, thank you! <3

local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

UserInputService.InputBegan:Connect(function(InputObject)
    if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
        local Animation = Instance.new("Animation") 
        Animation.AnimationId = "rbxassetid://5363193662" 
        local Track = Humanoid:LoadAnimation(Animation)
        Track:Play()
    end
end)

1 answer

Try this idk im not too good at scripting






	  script.Parent.Activated:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
       local Animation = Instance.new("Animation")
	        Animation.AnimationId = "rbxassetid://5363193662" 
Animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
        Animation:Play()
    end)
end)

script.Parent.Unequipped:Connect(function()
        animation:Stop()
end)

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