Getting nil from a primarypart (Rotate 3d using viewportframe)

im making my first inventory system and i wanted to make the part do like 360 as a viewing,
the problem is that it keeps giving me errors as there is no primary part in the model and i tried to make the script wait for the model to load but still it gives nil the first time then it does it correctly.

External Media
local viewportframe = script.Parent


viewportframe.ChildAdded:Connect(function(child)
	if child:IsA("Model") then
		while task.wait(0.001) do
			if viewportframe:FindFirstChildWhichIsA("Model") then
				child.PrimaryPart.CFrame *= CFrame.Angles(0,0.05,0)
			end
		end
	end
end)

*Future me: Fixed it btw

Just click on the Model and in the Properties click on “PrimaryPart”. You can now select a Part in the model from the Workspace window, or you can Alt left click on the model in the viewport window to select a Part there.
This sets the PrimaryPart.

yeah i did that but what i think happened is the primary part didn’t spawn soo it gives nil the first time then it works after that but ty

1 Like

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