Pet Position System

  1. What do you want to achieve? Keep it simple and clear! I am trying to position a pet to be behind the player.

  2. What is the issue? Include screenshots / videos if possible! Whenever it hatches the pet’s cframe is not changed or set

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I looked at multiple solutions on developer hub but they didn’t work

My current script:

    local PetM = _G.PetInfo
    local Attachment0 = hum.RootRigAttachment
    local Attachment1 = Instance.new('Attachment')
    local Constraint = Instance.new('WeldConstraint')
	
	
	
	local PosN = Instance.new('NumberValue')
	PosN.Parent = pet.PrimaryPart
	PosN.Value = petPos
	PosN.Name = 'PetPos'
	
	Constraint.Parent = pet.PrimaryPart
	Attachment1.Parent = pet.PrimaryPart
	Constraint.Part0 = hum
	Constraint.Part1 = pet.PrimaryPart
	print(hum.Position)
	print(pet.PrimaryPart.CFrame)
	pet.PrimaryPart.CFrame = hum.CFrame
	--pet.PrimaryPart.Position += Vector3.new(0,5,0)
	print(hum.CFrame)
	print(pet.PrimaryPart.CFrame)
	for i,part in pairs(pet:GetDescendants()) do
		if part:IsA('Part') or part:IsA('MeshPart') then
			part.CanCollide = false
			part.Position += Vector3.new(0,3.5,0)
			--part.Orientation += Vector3.new(0,-90,0)

			--part.Position = part.Position - (part.CFrame.LookVector * Vector3.new(3,0,0))
			--part.Position = part.Position + Vector3.new(0,0,(-3 + ((petPos - 1) * 3)))
		else
			continue
		end
	end
	
	
	player:WaitForChild('PetForce').Value += PetM[pet.Name].Power
	player:WaitForChild('Slots')[petPos].Value = true
	player.leaderstats:WaitForChild('JumpPower').Value = (player:WaitForChild('PetForce').Value + player:WaitForChild('DefaultForce').Value)
	

The pet spawns way behind the player where it was made

image

but works when you reset

image

if you can tell me why this is happening that would be really helpful
Thanks.

I’m not entirely sure but it could be the player was not found as the script plays instantly

Well it is because I walk over and hatch the egg

I was reading your script and you used Position. You should use CFrame.

Maybe something like this:

pet.PrimaryPart.CFrame = hum.CFrame * Offset

Offset is how much you want to move it. Using a CFrame.

Hope this helps.

Never mind I realised that it set the constraint before the position so just switching them around solved it

Thanks for everyone’s help