I need a fix for position

		-- Determine position for the new pet
		local existingPets = Character:GetChildren()
		local petSpacing = 5 -- Adjust spacing between pets
		local newPetPosition = Vector3.new(-5, 0, 5) -- Starting position offset for the first pet

		if #existingPets > 0 then
			for _, existingPet in pairs(existingPets) do
				if existingPet:IsA("Model") and PetBadges[existingPet.Name] then
					newPetPosition = newPetPosition + Vector3.new(petSpacing, 0, 0) -- Move position for each existing pet
				end
			end
		end

		-- Clone and position the new pet
		PetClone.Parent = workspace
		PetClone:SetPrimaryPartCFrame(Character.HumanoidRootPart.CFrame * CFrame.new(newPetPosition))

		-- Create BodyPosition and BodyGyro to follow the character
		local BodyPosition = Instance.new("BodyPosition", PetClone.MainPart)
		BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

		local BodyGyro = Instance.new("BodyGyro", PetClone.MainPart)
		BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)

		-- Update the pet's position and orientation
		task.spawn(function()
			while task.wait() do
				if Character then
					BodyPosition.Position = Character.HumanoidRootPart.Position + newPetPosition
					BodyGyro.CFrame = Character.HumanoidRootPart.CFrame
				end
			end
		end)

		-- Update character reference on respawn
		Player.CharacterAdded:Connect(function(newCharacter)
			Character = newCharacter
		end)

well the “Pets” arent positioned right, they go all on top of each other, and i wanted like 5 studs of distance

PS: this is a part of the script, if u want the full script tell me!

if existingPet:IsA("Model") and PetBadges[existingPet.Name] then

can you show more of the script about PetBadges?

this is all the script: (the badge thing works right)

--- Variables ---

local PetsFolder = game.ReplicatedStorage:FindFirstChild("PetsFolder")
local PetsModule = require(game.ServerScriptService.PetModule)
local BadgeService = game:GetService("BadgeService")

local PlayersUsing = {}
local Price = 500

-- Dictionary of pet names to their corresponding badge IDs
local PetBadges = {
	["pet_one"] = 2126467025449246,
	["pet_two"] = 567237262215735,
	["pet_three"] = 2543500802008691 -- Add entries for all pets
}

--- Buy Egg ---

script.Parent.ClickDetector.MouseClick:Connect(function(Player)

	local Character = Player.Character

	if PlayersUsing[Player] then 
		return 
	end

	PlayersUsing[Player] = true

	if Player.leaderstats.Cash.Value >= Price then
		Player.leaderstats.Cash.Value -= Price

		local PetsTable = {}

		-- Populate PetsTable based on rarity
		for _, Pet in pairs(PetsFolder:GetChildren()) do
			local Rarity = Pet.Rarity.Value

			for i = 1, PetsModule.Rarities[Rarity] do
				table.insert(PetsTable, Pet)
			end
		end

		local ChosenPet = PetsTable[math.random(1, #PetsTable)]
		local PetClone = ChosenPet:Clone()

		local HatchingGui = Player.PlayerGui:WaitForChild("HatchingGui")
		local EggImage = HatchingGui:FindFirstChild("Frame"):WaitForChild("EggImage")
		EggImage.Visible = true

		local Tick = tick()
		local Timer = 3

		-- Hatching Animation
		while tick() - Tick < Timer do
			EggImage.Rotation = 13
			script.Parent.sound.click:Play()
			wait(0.05)

			EggImage.Rotation = 0
			script.Parent.sound.click:Play()
			wait(0.05)

			EggImage.Rotation = -13
			script.Parent.sound.click:Play()
			wait(0.05)

			EggImage.Rotation = 0
			script.Parent.sound.click:Play()
			wait(0.05)
		end

		EggImage.Visible = false
		local PetImage = HatchingGui:FindFirstChild("Frame").PetImages:FindFirstChild(ChosenPet.Name)
		PetImage.Visible = true

		script.Parent.sound.eggsound:Play()
		wait(3)
		PetImage.Visible = false

		PlayersUsing[Player] = false

		-- Determine position for the new pet
		local existingPets = Character:GetChildren()
		local petSpacing = 5 -- Adjust spacing between pets
		local newPetPosition = Vector3.new(-5, 0, 5) -- Starting position offset for the first pet

		if #existingPets > 0 then
			for _, existingPet in pairs(existingPets) do
				if existingPet:IsA("Model") and PetBadges[existingPet.Name] then
					newPetPosition = newPetPosition + Vector3.new(petSpacing, 0, 0) -- Move position for each existing pet
				end
			end
		end

		-- Clone and position the new pet
		PetClone.Parent = workspace
		PetClone:SetPrimaryPartCFrame(Character.HumanoidRootPart.CFrame * CFrame.new(newPetPosition))

		-- Create BodyPosition and BodyGyro to follow the character
		local BodyPosition = Instance.new("BodyPosition", PetClone.MainPart)
		BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

		local BodyGyro = Instance.new("BodyGyro", PetClone.MainPart)
		BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)

		-- Update the pet's position and orientation
		task.spawn(function()
			while task.wait() do
				if Character then
					BodyPosition.Position = Character.HumanoidRootPart.Position + newPetPosition
					BodyGyro.CFrame = Character.HumanoidRootPart.CFrame
				end
			end
		end)

		-- Update character reference on respawn
		Player.CharacterAdded:Connect(function(newCharacter)
			Character = newCharacter
		end)

		-- Award the badge for this pet if it hasn't been awarded yet
		local BadgeID = PetBadges[ChosenPet.Name]
		print(BadgeID)
		--print(Player:HasBadge(BadgeID))
		if BadgeID --and not Player:HasBadge(BadgeID) 
		then
			print("giving badge")
			local success, err = pcall(function()
				BadgeService:AwardBadge(Player.UserId, BadgeID)
			end)
			print(success, err)

			if not success then
				warn("Failed to award badge: " .. err)
			end
		end
		end
	end)

do you have another script that puts pets into the character? this script sets their parent to workspace.

no i did not have another script

so if you look at your character for pets, you won’t find any, because you set their parent to workspace. try

local existingPets = workspace:GetChildren()

or try

PetClone.Parent = Character

EDIT: don’t do the first option, its simpler to have them children of the character

it is working, the pets are in place too

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.