Why does my code say my model doesn't have a primarypart?

  1. What do you want to achieve? I want my code to work (It doesn’t because it says the model doesnt have a primarypart

  2. **What is the issue?**Even tho it has a primarypart it says it doesn’t have
    Screen Shot 2022-05-10 at 11.02.07 PM
    Screen Shot 2022-05-10 at 11.02.28 PM

  3. What solutions have you tried so far? I searched yt

local rep = game:GetService("ReplicatedStorage")
local runs = game:GetService("RunService")
local model3D = require(rep:WaitForChild("Module3D"))
local tweeny = game:GetService("TweenService")
local uis = game:GetService("UserInputService")

local plr = game.Players.LocalPlayer
local cam = workspace.Camera
local pets = rep:WaitForChild("Pets")
local eggs = workspace:WaitForChild("Nidus")
local distance  = 40

local canhatch = nil
local ishatch = false
wait(3)

local function animatebilly(billboard , openorclose)
	if openorclose == true then
		tweeny:Create(billboard, TweenInfo.new(0.1),{Size = UDim2.new(15, 0,20, 0)}):Play()
	else
		tweeny:Create(billboard, TweenInfo.new(0.2),{Size = UDim2.new(0,0,0, 0)}):Play()
		wait(.3)
		billboard.Enabled = false
	end
	wait(1)
end

for i,v in pairs(eggs:GetChildren()) do
	local eggpets = pets:FindFirstChild(v.Name)
	
	if eggpets ~= nil then
		
		
		local billboardtemp = script.Template:Clone()
		local container = billboardtemp:WaitForChild("Cointainer")
		local frame = container:WaitForChild("Main_Frame")
		local template = frame:WaitForChild("Template")
		local billboardegg = script.Parent.Parent.Eggboards
		local port = template:WaitForChild("Port")
		
		billboardtemp.Adornee = v.EggMesh
		billboardtemp.Name = v.Name
		billboardtemp.Enabled = true
		billboardtemp.Parent = billboardegg
		
		local petz = {}

		for x, pet in pairs(eggpets:GetChildren()) do
			table.insert(petz, pet.Rarity.Value)

		end
		table.sort(petz)
		
		for i = 1, math.floor(#petz/2) do
			local j = #petz - i + 1
			petz[i], petz[j] = petz[j], petz[i]
		end
		
		for _,rarity in pairs(petz) do
			for _, pet in pairs(eggpets:GetChildren()) do
				if pet.Rarity.Value == rarity then
					local rarity = pet.Rarity.Value



					local clonedtemp = template:Clone()
					clonedtemp.Name = pet.Name

					clonedtemp.Rarity.Text = tostring(pet.Rarity.Value).."%"
					clonedtemp.Visible = true
					clonedtemp.Parent = frame

					local petmodel = model3D:Attach3D(clonedtemp.Port,pet:Clone())
					petmodel:SetDepthMultiplier(1.2)
					petmodel.Camera.FieldOfView = 5
					petmodel.Visible = true

					runs.RenderStepped:Connect(function()
						petmodel:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
					end)
					break
				else
					continue
				end
			end
		end
		
		
			
			
		runs.RenderStepped:Connect(function()
			if plr:DistanceFromCharacter(v.EggMesh.PrimaryPart.Position) < distance then
					if billboardtemp.Name ~= v.Name then
					canhatch = true
					
					animatebilly(billboardtemp, true)
					billboardtemp.Enabled = true
					else
						canhatch = true
					
					animatebilly(billboardtemp, true)
					billboardtemp.Enabled = true
						
					end
			else
				animatebilly(billboardtemp, false)
				
				canhatch = false
			end
			
		end)
	end
end

local function hatch1(pet,egg)
	print(pet)
	local eggmesh = egg:FindFirstChild("EggMesh"):Clone()
	for i,v in pairs(eggmesh:GetChildren()) do
		if v:isA("BasePart") then
			v.Anchored = true
			v.CanCollide = false
			runs.RenderStepped:Connect(function()
				local cf = CFrame.new(0, 0,-eggmesh.PrimaryPart.Size.Z * 2)
				eggmesh:SetPrimaryPartCFrame(cam.CFrame * cf)
			end)
			eggmesh.Parent = cam
		end
	end
end


uis.InputBegan:Connect(function(input)
	local billboardtemp = script.Template
	local clonedtemp = billboardtemp.Cointainer.button
	if input.KeyCode == Enum.KeyCode.E then
		if canhatch == true and plr.Character ~= nil and ishatch == false then
			local plrps = plr.Character.HumanoidRootPart.Position
			local nearsetg
			for i,v in pairs(eggs:GetChildren()) do
				if v.PrimaryPart == nil then
					print(v:GetFullName(), "don't have a PrimaryPart!")
				end

				if nearsetg.PrimaryPart == nil then
					print(nearsetg:GetFullName(), "don't have a PrimaryPart!")
				end

				if (plrps - v.PrimaryPart.Position).Magnitude < (nearsetg.PrimaryPart.Position - plrps).Magnitude then
					nearsetg = v
				end
			end
			local result = rep:WaitForChild("EggHatchingRemotes")	:WaitForChild("hatchserver"):InvokeServer(nearsetg)
			if result ~= nil then
				ishatch = true
				hatch1(result,nearsetg)
				wait(3)
				ishatch = false
			end
		end

	end
	
end)
1 Like

Well, have you set the primary part of the model, like in the properties menu? Sound obvious but it’s good to check.

If that isn’t the reason then you’re going to have to be a lot more specific than “I want my code to inform my model has a primary part”, Like, what does the script do, what lines do what, why do you need the primary part.

it is the main client of my display system. I checked my properties and it does have a primarypart.

By the looks of things, the script is searching through the children of eggs and is finding one without a PrimaryPart. The output you showed is referring to something with another name than EggMesh. Thus, this is happening because of a different object.

2 Likes

As @welololol & @Bergan have said, it’s looking for Nidus.Basic Nidus in one of these lines. Change “don’t have…” to “egg doesn’t have a primary part” and “nearsetg doesn’t have a primary part” to narrow your search.

2 Likes

Nevermind, i had a model inside a model. So in my code i made v.Secondarymodel.PrimaryPart.Position

2 Likes