How do you prefer to handle tool animations when scripting a tool?

I’m currently trying to do tool animations but it’s very buggy and doesn’t always replicate smoothly between server and client when just doing them in the tool so I wanna hear how you guys do them mostly?

should I instead handle the animations in a server script and have the local script just fire animations? or is there a way to do tool animations in localplayerscripts/characterscripts?

below is my script any I already know that trying to use .looping doesn’t work properly but when I try to make the functions just play the non looping animations they begin to bug and it still doesn’t play properly serverside

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
end

If you are doing this on the server, don’t. The client has full network ownership of their character, which means anything done to it will replicate, including animations. That’s probably why it’s not smooth.

1 Like

this is done fully in the local script of a tool but even then it still seems to bug out server side

and what i mean by that is even if I have the animations not looping and just have functions setup to play the animations every time they fire the animations work client side but just stop working after running one time server side