My animations are new instances in a guns local script and this works fine for have them on both server side and client side. And while everything is working fine client side with starting and stopping animations I’ve noticed that after I have finished firing the animation continues to loop Server side no matter what. It will try to play over other animations and even play when the weapon is unequipped. Any ideas on how to fix this?
StopAnimation1 (Firing Animation)
local function stopAnimation1()
isPlaying = false
if ammo == 0 then
canReload = true
track2:Play()
if not ammoDebounced then
ammoDebounced = true
playAnimation4()
task.wait(1.25) -- Adjust the time accordingly
ammoDebounced = false
end
track2:Play()
end
if track1 then
track1.Looped = false
track1.Stopped:Wait()
gunshotS()
boltcomboS()
task.wait(0.03)
track1:Stop()
end
if track2 then
track2:Play()
task.wait(2)
end
end
playAnimation1 (Firing Animation)
local function playAnimation1()
if not isPlaying then
isPlaying = true
if canFire and canReload then -- Add a condition to check if the player can fire
canFire = false -- Prevent firing until delay is over
canReload = false -- Prevent reloading while firing
local humanoid = game.Players.LocalPlayer.Character.Humanoid
if ammo > 0 then
if track4 then
track4:Stop()
end
if track2 then
track2:Stop()
end
if track3 then
track3:Stop()
end
track1 = humanoid:LoadAnimation(anim1)
track1.Priority = Enum.AnimationPriority.Action
track1.Looped = true
track1:Play()
track1:AdjustSpeed(4 * fireRate)
task.wait(0.07)
gunshotP()
boltcomboP()
while isLooping and isPlaying do
ammo = ammo - 1
if ammo < 0 then
ammo = 0
end
updateAmmoCount()
if ammo == 0 then
gunshotS()
boltcomboS()
stopAnimation1() -- Stop animation when ammo is zero
return
end
task.wait(fireRate)
-- Get the start position of the laser beam
local startPosition = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
-- Fire the LaserFired remote event to notify the server and other clients
local mouse = game.Players.LocalPlayer:GetMouse()
local endPosition = mouse.Hit.p
eventsFolder.WeaponFiredEvent:FireServer(startPosition, endPosition)
playMuzzleEffect()
end
task.wait(fireRate) -- Add a firing delay
canFire = true -- Allow firing again after the delay
else
gunshotS()
boltcomboS()
playAnimation4()
end
task.wait(fireDelay) -- Add a delay before the player can fire again
canReload = true -- Allow reloading after the delay
end
end
track1.Looped = false
track1:Stop()
end
I have the isLooping which is called in PlayAnimation1 but trying to alter this in stopAnimation1 just completely breaks it