Client cant find the primary part

The client is unable to find the primarypart which isn’t allowing the pet’s movement to be shown. If I do the same exact thing on the server it works but the movement is choppy. If you are a new player this doesn’t happen but something breaks. (My guess leaving at a certain point breaks it.) The pet does exist but the client is unable to find it or the primary pet.

	game:GetService("RunService").Stepped:Connect(function()
		for _, pet in pairs(game:GetService("CollectionService"):GetTagged("PetModel")) do
			local tag = pet:FindFirstChild"Owner"
			
			if tag then
				local plr = tag.Value
				
				if plr and plr.Character and pet.PrimaryPart then
					local offset = CFrame.new(3,2,0)
					
					if plr.Character.Humanoid.Sit then
						offset = CFrame.new(0,-1,-.5)
					end
					
					pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(plr.Character.PrimaryPart.CFrame*offset, .1))
				end
				
				if pet.PrimaryPart == nil then
					pet:Destroy()
				end
			end
		end
	end)
1 Like

That is odd. Can I see your output? Check if some other script is modifying the primary part.

Without if pet.PrimaryPart

pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(plr.Character.PrimaryPart.CFrame*offset, .1))

this line errors.

Does it say “PrimaryPart is not a valid member of model” or “:SetPrimaryPartCFrame can’t be done or something”

“Attempt to index nil with CFrame”

The primarypart is printing nil

That is so odd. If there wasn’t a primary part then it would complain about the method SetPrimaryPartCFrame also.

Yeah it’s something breaking on the client side cause it does work on the server. I know for sure the primary part does exist it just can’t find it.

Are there multiple models of “pets”? Possible that a model tagged as “PetModel” might not have a PrimaryPart or “Owner” value inside of it.

There are but they all have it, if a new player joins and buys a pet it will work fine but after some time, something breaks and I’m not sure what it is. Maybe it could be related to:

But this method didn’t work for me.

Are you using StreamingEnabled? One thing I’ve noticed is that when something is streamed out and then back in it won’t reset it’s primarypart. So it will be set on initial load but not once streamed in/out.

1 Like

I am using StreamingEnabled, what should I do to fix that?

Honestly I think it’s a bug but I didn’t get around to posting a bug report for it yet. It only gets cleared on the client but obviously stays fine on the server. As a fix the only thing you can really do is find the child by name and reset it yourself. If the primarypart is always named the same thing then that should be trivial (but yes annoying and kinda hacky). Maybe I’ll go post that bug report now, haha

Posted bug report. Like I said I worked around it by just finding by name. You can test your code to see if that fixes your issue and if so then it’s probably the same bug. Otherwise it might be something different for you.
https://devforum.roblox.com/t/engine-bugs-model-primarypart-is-lost-when-streamed-out-and-then-back-in/606251

1 Like

Well here’s the thing if your setting the CFrame on client- it’s not going to replicate to other players.

The Choppy movements will likely be the same on client, because network ownership is a bit irrelevant here. It depends more on your cframe implementation

This bug still exists for me. I have a model on the server whose PrimaryPart is set before parenting to the workspace. I am watching the folder it gets parented to for ChildAdded. When that fires I am then trying to get the PrimaryPart of that model and it prints nil while inspecting the properties both on servre and client shows it as being set properly.

I also ran into this error today - primary part is already set before being parented to workspace, yet will read nil from client