Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

PrimaryPart a nil value?

Why am I getting this error?

Workspace.Oven.OvenDoor.Handle.Script:7: attempt to index field 'PrimaryPart' (a nil value)

local Handle = script.Parent
local OvenDoor = Handle.Parent.OvenDoor

function openOven()
	for i = 1, 12 do
		print("Opening...")
		OvenDoor:SetPrimaryPartCFrame(script.Parent.Parent.PrimaryPart.CFrame * CFrame.Angles(0, 0, math.rad(5)))		
		wait()
	end
end

Handle.ClickDetector.MouseClick:connect(openOven)

3 comments

0

The primary part isn't set

0

And how might I set it?

0

set the primary part, by going to explorer, clicking on model, go to properties, click primary part, and then click a part in the model (in explorer)

1 answer

✓ Accepted answer

You need to set the primary part for the model. You can do this one of two ways:

local Model = workspace.Model;
Model.PrimaryPart = Model.SomePart;

Or, you can manually set it:

  • Click the model in explorer.
  • Click the blank input box next to the text "PrimaryPart" in the properties section. The mouse cursor should change.
  • Finally, click on a part that is a child (descendant) of the model that you want to be the primary part.

This discussion is preserved as it was. New answers, comments, and votes are closed.