I am adding a mining system into my game the only issue is I don’t know how to script so I had to watch a tutorial on how to make this, everything works but there is a bug, how the pickaxe/animation works are when your left mouse button is held down the animation plays, but if you don’t have your pickaxe out then the animation should not play if the mouse is being held down.
I see, looking at the code for the animation, the connection isn’t being disconnected and/or it isn’t checking if the tool is equipped. Try this:
local uis = game:GetService("UserInputService")
local Equipped = false
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local gripAnim = humanoid:LoadAnimation(script.GripAnim)
local hitAnim = humanoid:LoadAnimation(script.HitAnim)
local pickaxe = script.Parent
local mouseHeldRE = pickaxe:WaitForChild("MouseHeldEvent")
uis.InputBegan:Connect(function(input, processed)
if not Equipped then return end
if processed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
mouseHeldRE:FireServer(true)
hitAnim:Play()
end
end)
uis.InputEnded:Connect(function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
mouseHeldRE:FireServer(false)
hitAnim:Stop()
end
end)
pickaxe.Equipped:Connect(function()
Equipped = true
gripAnim:Play()
end)
pickaxe.Unequipped:Connect(function()
Equipped = false
gripAnim:Stop()
end)