Pet bouncing when walking

How would i make the script so that the pet bounces up and down whenever the player is walking like most other games with pets. I’ve tried getting help from chatgpt and i’ve looked at other posts about this but nothing works.

The pet is a MODEL. The pet has a PrimaryPart called Root which is welded to the players humanoidrootpart so the pet follows.

Problems which have occured is that because of the weld (im guessing) the player bounces up and down instead of the pet. So how would I make only the pet bounce when the player walks?

-- Services
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

-- Function to create weld between pet and HumanoidRootPart
local function weldPetToPlayer(pet, player)
	-- Ensure both the pet and player have the required parts
	local petPart = pet:FindFirstChild("Root") -- Replace with your pet's part
	local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")

	if petPart and humanoidRootPart then
		-- Create a weld constraint
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = humanoidRootPart
		weld.Part1 = petPart
		weld.Parent = petPart

		-- Position the pet relative to the player's HumanoidRootPart (adjust as needed)
		pet:SetPrimaryPartCFrame(humanoidRootPart.CFrame * CFrame.new(0, 3, 0)) -- Example: Position the pet above the player
	end
end

-- Function to unanchor all parts and meshparts inside a pet model
local function unanchorPartsInPet(pet)
	for _, descendant in ipairs(pet:GetDescendants()) do
		if descendant:IsA("BasePart") then
			descendant.Anchored = false
		end
	end
end

-- Function to weld every part inside the pet to the pet's Root part
local function weldPartsToRoot(pet)
	local rootPart = pet:FindFirstChild("Root") -- Replace with your pet's root part if needed
	if rootPart then
		for _, descendant in ipairs(pet:GetDescendants()) do
			if descendant:IsA("BasePart") and descendant ~= rootPart then
				-- Create a weld for every part except the Root part
				local weld = Instance.new("WeldConstraint")
				weld.Part0 = rootPart
				weld.Part1 = descendant
				weld.Parent = descendant
			end
		end
	end
end

-- Predefined locations for the pets
local petLocations = {
	Vector3.new(0, -1, 7),  -- First pet location
	Vector3.new(3, -1, 7),  -- Second pet location
	Vector3.new(-3, -1, 7), -- Third pet location
}


-- Player added
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		-- Wait for the character's model and the pets to load
		local waitForPetsData = player:WaitForChild("SaveData"):WaitForChild("PetsData")

		-- Find all pets (assuming they are children of the character)
		local petIndex = 1
		for _, pet in ipairs(character:GetChildren()) do
			-- Check if the pet is a model (or customize as needed)
			if pet:IsA("Model") then
				-- Unanchor all parts inside the pet
				unanchorPartsInPet(pet)

				-- Move pet to its predefined location based on the index
				local petLocation = petLocations[petIndex]
				pet:MoveTo(character.HumanoidRootPart.Position + petLocation)

				-- Weld all parts to the pet's Root part
				weldPartsToRoot(pet)

				-- Call the weld function for the pet to the player
				weldPetToPlayer(pet, player)
				
				

				-- Increment the pet index to ensure each pet gets a unique location
				petIndex = petIndex + 1
				if petIndex > 3 then
					petIndex = 1  -- Loop back if there are more than 3 pets
				end
			end
		end
	end)
end)