I was animating and scripting a tool for it to be a click-and-hold tool, which means it should loop the animation when you click and hold your left mouse button, but it should immediately stop once you release it. I got the animations done and everything, but I need the "looping" part. How do you do that?
Oh, and for some reason, the animation plays even if you don't have the tool equipped.
Here's the local script I'm using:
wait(.2)
local tool = script.Parent
local debounce = true
local player = game.Players.LocalPlayer
local character = player.Character
local idle
local attack
local music = script.Parent.Hitbox["Sound"]
tool.Equipped:Connect(function()
idle = character.Humanoid:LoadAnimation(script.Parent.Idle)
idle:Play()
end)
tool.Unequipped:Connect(function()
idle:Stop()
end)
-- le animating
local InputService = game:GetService("UserInputService")
InputService.InputBegan:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
attack = character.Humanoid:LoadAnimation(script.Parent.Attack)
attack:Play()
music:Play()
music.TimePosition = 0.5
end
end)
InputService.InputEnded:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
attack = character.Humanoid:LoadAnimation(script.Parent.Attack)
attack:Stop()
music:Stop()
end
end)

6 comments
How you make that "titles" I wanna know. I'm a scripter and I make a explanation too. So this will be really helpful.
Oh! You just have to do on the editor a #Text
There was an error. The script doesn't know what game.Players.LocalPlayer.Character was I think.
Nevermind, fixed it.
Have a nice day ;)
Also, accept my answer please.