Animation Stop Not Functioning Properly

Hello,
Recently, I made a script that stops playing an animation when the player gets out of the seat however it has come to my attention that the script is bugged and when the player gets out of the seat animations for all players are stopped even if they did not get up. Assistance on this would be appreciated.

local function stopAllAnimations()
	local character = script.Parent.Parent
	local humanoid = character:WaitForChild("Humanoid")
	if not humanoid then return end

	-- Stop all animations
	for _, track in ipairs(humanoid:GetPlayingAnimationTracks()) do
		track:Stop()
	end
end
seat1:GetPropertyChangedSignal("Occupant"):Connect(function()	
	local character = game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAdded:Wait()

	local playingAnim1 = character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(newAnim1)
	local occupant = seat1.Occupant
	if occupant == character:FindFirstChild("Humanoid") then
		 ANIMPLAYING = true
		playingAnim1:Play()
	end
	if occupant == nil then
		 ANIMPLAYING=false
		stopAllAnimations()
	end
end)

if this script is on the player, im pretty sure you can just use Humanoid.Sit

also load the animations first, then use it in the functions
so just check if the Humanoid.Sit is true and play the animation, else stop it

You would probably need to specify the character in the stopAllAnimations() function.

but i did how should i do it -----

that would just be changing a way to write my code – the problem still would persist

Is the script being added to all characters? With the current code, every time the seat becomes empty, all characters with the script have their animations stopped, regardless of which character left the seat.

It might be better to create a connection with Humanoid.StateChanged:Once when you start playing the animation, then once the state changes out of sitting you stop the animations. (Instead of trying to use the change in the seat’s occupant to trigger this.)