-- Local Functions

local function onCharacterAdded(character)
	wait(1) -- You want to wait for the Animate script to load and run
	
	local humanoid = character:WaitForChild("Humanoid")
	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingTracks:Stop(0)
	end
 
	local animateScript = character:WaitForChild("Animate")
	
	for _, anim in ipairs(replacementAnimations) do
		if not anim.isLoaded then continue end

		local animations = animateScript:WaitForChild(anim.name):GetChildren()
		-- Overwrite the IDs of all idle animation instances
		for _, animVariant in ipairs(animations) do
			animVariant.AnimationId = anim.id

			-- If you really want to prevent the animations from being changed by something else you could do this too
			animVariant:GetPropertyChangedSignal("AnimationId"):Connect(function()
				animVariant.AnimationId = anim.id
			end)
		end
	end
	
	-- Stop all currently playing animation tracks on the player
	for _, playingAnimation in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingAnimation:Stop()
		playingAnimation:Destroy()
	end
end
 
local function onPlayerAdded(player)
	--Only run this code if an animation actually is loaded in. 
	local character = player.Character or player.CharacterAdded:wait()
	onCharacterAdded(character)
end

