Hello!
I’ve made a script that seems to work just fine for everything except when I unequip the tool the animation doesn’t stop. How can I go about fixing this issue.
LocalScript:
local Tool = script.Parent
local Animation = Tool.Animation
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local rounds = 8
local reloading = false
Tool.Equipped:Connect(function()
local Character = Tool.Parent
local Humanoid = Character.Humanoid
local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
player.PlayerGui.GunHud.Enabled = true
end)
tool.Unequipped:Connect(function()
local Character = player.Character
local Humanoid = Character.Humanoid
local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Stop()
player.PlayerGui.GunHud.Enabled = false
end)
tool.Activated:Connect(function()
if reloading == false and rounds >= 1 then
tool.firesound:Play()
if rounds >= 1 then
wait(.1)
rounds = rounds -1
end
if mouse.Target.Parent then
script.Parent.RemoteEvent:FireServer(mouse.Target.Parent)
end
player.PlayerGui.GunHud.Ammo.Text = rounds.."/8"
end
if rounds == 0 then
reloading = true
tool.reload:Play()
wait(1.6)
rounds = 8
reloading = false
player.PlayerGui.GunHud.Ammo.Text = rounds.."/8"
end
end)
Thank you!