I can’t take this anymore I’ve used ai and searched past forums and I can’t find a single solution.
My problem is in the title, I just need all the tool animations to stop playing when the tool is dropped. please ignore my messy code btw ik i suck
Here’s my current code:
local tool = script.Parent
local animationFolder = tool:WaitForChild("Animations")
local handle = tool.Handle
local player = game:GetService("Players").LocalPlayer
local idleAnim = animationFolder:WaitForChild("Idle")
local fireAnim = animationFolder:WaitForChild("Fire")
local equipAnim = animationFolder:WaitForChild("Equip")
local reloadAnim = animationFolder:WaitForChild("Reload")
local idleTrack
local fireTrack
local equipTrack
local reloadTrack
-- Animation state management
local currentAnimation
local isEquipped = false
local animator
local humanoid
local mouse
local uis = game:GetService("UserInputService")
local maxB = 20
local bullets = maxB
local reloading = false
local shooting = false
local function reload()
if not reloading and bullets < maxB then
reloading = true
if not reloadTrack then
reloadTrack = animator:LoadAnimation(reloadAnim)
reloadTrack.Priority = Enum.AnimationPriority.Action
end
if idleTrack then
idleTrack:Stop()
end
handle.reload:Play()
reloadTrack:Play()
reloadTrack.Looped = false
-- Return to idle after firing
wait(reloadTrack.Length)
bullets = maxB
reloading = false
end
end
tool.Equipped:Connect(function(playerMouse)
local character = player.Character or player.CharacterAdded:Wait()
humanoid = character:WaitForChild("Humanoid")
animator = humanoid:WaitForChild("Animator")
mouse = playerMouse
isEquipped = true
if not equipTrack then
equipTrack = animator:LoadAnimation(equipAnim)
equipTrack.Priority = Enum.AnimationPriority.Action
end
equipTrack:Play()
equipTrack.Looped = false
wait(equipTrack.Length) -- Wait for equip animation to finish
if not idleTrack then
idleTrack = animator:LoadAnimation(idleAnim)
idleTrack.Priority = Enum.AnimationPriority.Idle
end
idleTrack:Play()
currentAnimation = idleTrack
playerMouse.Button1Down:Connect(function()
if not reloading and not shooting then
shooting = true
while shooting do
if not fireTrack then
fireTrack = animator:LoadAnimation(fireAnim)
fireTrack.Priority = Enum.AnimationPriority.Action
end
if bullets > 0 and not reloading then
bullets -= 1
else
reload()
shooting = false
break
end
-- Stop idle animation when firing
if idleTrack then
idleTrack:Stop()
end
fireTrack:Play()
fireTrack.Looped = false
tool.MouseEvent:FireServer(playerMouse.Hit.Position)
task.wait(.11)
end
end
end)
playerMouse.Button1Up:Connect(function()
if shooting then
shooting = false
if isEquipped then
idleTrack:Play()
currentAnimation = idleTrack
end
end
end)
end)
tool.Unequipped:Connect(function()
isEquipped = false
if idleTrack then
idleTrack:Stop()
end
if equipTrack then
equipTrack:Stop()
end
if fireTrack then
fireTrack:Stop()
shooting = false
end
end)
game:GetService("UserInputService").InputBegan:Connect(function(input, processed)
if not processed then
if input.KeyCode == Enum.KeyCode.R then
reload()
end
end
end)