Problem with pet following script

what the hell? are you sure your pet model even has children then? there’s genuinely no reason i could see anything wrong with that, are there any errors in the output?

use Current: Server in play mode to look inside the characters children, and look for the pet. if you find the pet and there are no children in the model inside the player you know something got ####'d up

Got it to print by firing an event from server and sending the petmodel as the parameter.

local PetsEquipped = script.Parent:WaitForChild("EquippedPets")
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local humRootPart = Character:WaitForChild("HumanoidRootPart")
local Event = game:GetService("ReplicatedStorage").Pets.Events.EquipPet

local function GetPointOnCircle(CircleRadius, Degrees)
	return Vector3.new(math.cos(math.rad(Degrees)) * CircleRadius, 0, math.sin(math.rad(Degrees)) * CircleRadius)
end

local function petFollow(pet, Pos, bp, bg)
	spawn(function()
		print(pet.PrimaryPart.Size)
		RunService.RenderStepped:Connect(function()
			if pet.Parent == nil then
				print("ITS NIL")
			end
			pet.Parent = PetsEquipped
			bp.Position = (humRootPart.CFrame * CFrame.new(Pos)).p - Vector3.new(0, humRootPart.Size.Y / 2, 0) + Vector3.new(0, pet.PrimaryPart.Size.Y, 0)
			bg.CFrame = humRootPart.CFrame
		end)
	end)
end

 Event.OnClientEvent:Connect(function(child)
	for i,v in pairs(child:GetChildren()) do
		print(v, v.Parent)
	end
	local bp, bg = Instance.new("BodyPosition"), Instance.new("BodyGyro")
	
	bg.D = 750
	bg.MaxTorque = Vector3.new(25000, 25000, 25000)
	bg.P = 5000
		
	bp.D = 400
	bp.MaxForce = Vector3.new(1250, 10000, 1250)
	bp.P = 10000
	
	bp.Parent, bg.Parent = child.PrimaryPart, child.PrimaryPart
	
	petFollow(child, GetPointOnCircle(5, 360/#PetsEquipped:GetChildren()), bp, bg)
end)

image

alright, thats progress; what is the primary part of your model? like what is the name

make sure not to forget this

I already did and there’s children but pet is “destroyed(parent goes to nil)” so there’s no more pet.

well thats the issue… the pet’s getting destroyed; how are you going to reference a primarypart from a model that no longer exists

That’s the problem but how do I fix it knowing I can’t anchor the parts? Bodyposition only works on non-anchored parts.

you just don’t destroy the pet?..

The pet’s destroying naturally cuz parts arent anchored so they fall off the map and destroys…?

alright. you need to weld the pet together via a plugin of some sort, then after that inside a script weld the pets primary part to the players character, then after you have created body positions / gyros you destroy the weld

OH I found the problem : I am cloning and parenting the pet from the server and doing bodygyro/bodyposition from client; Server doesnt register this client thingy so pet is falling off map and is destroyed.

1 Like