Animation stuck looping Server side after firing but not client side

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

I’ve had this problem before. Animation properties don’t replicate, according to my knowledge, if you change .Looped on the server, it won’t change on the client.

According to the documention, changing it after it is playing will not take effect, something to note. I fixed my problem (similar to this) by playing the animations locally on every client.

If it still doesn’t fix your problem, make sure the actual animation you published is looping if you want it loop, and not looping if you don’t want it to, so you don’t have to change it through script.

1 Like

Just did some testing turns out if the animation has no loop then it ends server side after running the first time but if it is looped itll play for forever. If I wanted to make them play client side should I change the animations from being new instances to just being the premade animation holder thingys?

how would I do this? do you somehow make the animations play in starterplayerscripts? I can’t figure out how to do this any other method besides the one I’ve been using.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.