Issue with Pets going really high/jumping when I jump

Hello!

I am having this issue that I am unable to solve, and am stuck on. I am not sure where the issue is inside the script, but I am pretty sure it’s not the raycast but I am not sure. The Script and an Example video on what I mean are down below, if you need anymore information I will gladly give it!

Video of what I mean:
(Used psx pets as example)


Script:

local runService = game:GetService("RunService")
local playerPets = workspace:WaitForChild("Player_Pets")
local circle = math.pi * 2
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
wait(2)
local function getPosition(angle, radius)
	local x = math.cos(angle) * radius
	local z = math.sin(angle) * radius
	return x, z
end
local Paramas = RaycastParams.new()
Paramas.FilterDescendantsInstances = {game.Workspace.Player_Pets:GetDescendants(), game.Workspace.Annexsohn}
Paramas.FilterType = Enum.RaycastFilterType.Blacklist
Paramas.IgnoreWater = true;
function GetY(pos)
	if workspace:Raycast(pos + Vector3.new(0,15,0),Vector3.new(0,-100,0),Paramas) then
		return workspace:Raycast(pos + Vector3.new(0,15,0),Vector3.new(0,-100,0),Paramas).Position.Y - 3.15
	else
		return library.LocalPlayer.Character.PrimaryPart.Position.Y
	end
end
local function positionPets(character, folder)
	for i, pet in pairs(folder:GetChildren()) do
		local radius = 5
		local angle = i + (circle / #folder:GetChildren())
		local x, z = getPosition(angle, radius)
		local sin = (math.sin(15 * time() + 1.6)/.5)+1
		local cos = math.cos(7 * time() + 1)/4

		local petData = require(game.ReplicatedStorage:FindFirstChild("PetModels"):FindFirstChild(pet.Name):FindFirstChild("petData"))
		if character.Humanoid.MoveDirection.Magnitude > 0 then
			if petData["flys"] == false then
				pet.CFrame = pet.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, GetY(library.LocalPlayer.Character.PrimaryPart.Position)+sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1)
			else
				pet.CFrame = pet.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, GetY(pet.Position)/2+math.sin(time()*3)+1, z),0.1)
			end 
		else
			if petData["flys"] == false then 
				pet.CFrame = pet.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, GetY(pet.Position), z) ,0.1)
			else
				pet.CFrame = pet.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, GetY(pet.Position)/2+math.sin(time()*3)+1, z) ,0.1)
			end
		end
	end
end
library.RunService.RenderStepped:Connect(function()
	for _, PlrFolder in pairs(playerPets:GetChildren()) do
		local Player = game.Players:FindFirstChild(PlrFolder.Name) or nil
		if Player ~= nil then
			local character = Player.Character or nil
			if character ~= nil then
				positionPets(character, PlrFolder)
			end
		end
	end
end)

Thanks! Any help will be very much appreciated.

If anyone knows, anything will be greatly appreciated! Thanks :smile:

Sorry I’m not following your issue. Is the problem that these pets are jumping when you jump or is it that they are jumping to high? Or is the issue the last few seconds of the video where these pets are much higher above the character while on the staircase?

So, the issue is just very weird and to me its very hard to explain. Cause If I move the baseplate to 0 instead of -8 which is where it originally is, it does the same thing like going on any part. And the other issue is that it follows like my Characters Y or something when the Raycast should be doing it all. Here is a game file if you want to test around, you’ll notice my issue basically immediately

game.rbxl (44.0 KB)