Animations not playing on server and anim:Stop() doesnt work

I have a windscreenwiper animation that plays as intended on the client but doesn’t play on the server even though it’s inside a server script. The animation also does not stop when I do animation:Destroy() which is primarily impossible.

Server script:

WipeEvent.OnServerEvent:Connect(function(player, cmd)
	local WiperAnimationFront = Instance.new("Animation")
	WiperAnimationFront.AnimationId = "rbxassetid://13041346049"
	WiperAnimationFront.Parent = script.Parent.WipersFront

	local WiperAnimationBack = Instance.new("Animation")
	WiperAnimationBack.AnimationId = "rbxassetid://13041346049"
	WiperAnimationBack.Parent = script.Parent.WipersBack
	
	local WiperAnimB = AnimatorCoachB:LoadAnimation(WiperAnimationFront)
	local WiperAnimF = AnimatorCoachF:LoadAnimation(WiperAnimationBack)
	if CoachB.IsFrontCoach.Value == true and cmd == "Enable" then
		WiperAnimB:Play()
	elseif CoachB.IsFrontCoach.Value == true and cmd == "Disable" then
		WiperAnimationFront:Destroy()
	elseif CoachF.IsFrontCoach.Value == true and cmd == "Enable" then
		WiperAnimF:Play()
	elseif CoachF.IsFrontCoach.Value == true and cmd == "Disable" then
		WiperAnimationBack:Destroy()
	end
end)

The client script is pointless to show because it only sends a cmd variable

Destroying the Animation object does not mean it will stop. You must destroy the AnimationTrack to make it stop.
So do

WiperAnimB:Destroy()

instead of

WiperAnimationFront:Destroy()

I would also like to note that it is not good practice to continuously load animation tracks without destroying them. Once you reach the limit of 256 tracks, your script will stop working and no animations will play.

I am unsure as to why the animation would not be playing on the server. Is the game under your profile and is the animation also under your profile? If the game is under another profile or a group and the animation is uploaded under your profile, then only you will see it.

1 Like

Oh right I thought about trying that but I didn’t think that destroying an animation track would work, Thanks!

I did what you said and the animation still does not stop oddly. whenever the “Disable” cmd is received it just does that line of code that checks if it “Disabled” (I know this because I put a print there). The game is under my profile. Instead of firing a remote event from the client would it be possible to get the playergui through the server and check when the player presses a button. I can get the player in this script with VehicleSeat.Occupant

When are these values changed? If they are never changed, then it may not be functioning as intended.
I would also like to note that each command will only be able to turn off one wiper animation at a time. I unsure whether this is intentional or not.

This is intended

CoachF.IsFrontCoach.Value

is set to true at the moment

CoachB.IsFrontCoach.Value

is set to false.
These are values in which are not changed by another script right now but later on in my development they will start changing.

I fixxed the animation stopping by changing the cmd value to the server script

WipeEvent.OnServerEvent:Connect(function(player)
	if IsWiping == false then
		WiperAnimB:Play()
		IsWiping = true
	elseif IsWiping == true then
		WiperAnimB:Stop()
		IsWiping = false
	end
end)

now Im just unsure why its not playing on the server