My script isn't working!

So I get this error below.

  10:44:10.192  Model:SetPrimaryCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this

And my script is

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local PosX
local PosY
local PosZ
	
local Model
local Button = script.Parent.TextButton
	
local GridSize = 2

local CanStart = true
local isPlacing = nil
local CanPlace = nil

local function Snap()
	PosX = math.floor(Mouse.Hit.X / GridSize + 0.5) * GridSize
	PosY = 3
	PosY = math.floor(Mouse.Hit.Z / GridSize + 0.5) * GridSize
end

local function Placement()
	if isPlacing and CanPlace then
		local PlacedModel = Model:Clone()
		PlacedModel.Parent = workspace.PlacedObjects
		
		isPlacing = false
		CanPlace = false
		CanStart = true
		
		Model:Destroy()
	end
end

local function Movement()
	Mouse.TargetFilter = Model
	
	Snap()
	
	Model:SetPrimaryPartCFrame(CFrame.new(PosX, PosY, PosZ))
end


local function StartPlacementWoodBlock()
	if CanStart then
		Model = game:GetService("ReplicatedStorage").WoodBlock:Clone()
		Model.Parent = workspace
		isPlacing = true
		CanPlace = true
		CanStart = false
		
		Mouse.Move:Connect(Movement)
	end
end

Mouse.Button1Down:Connect(Placement)
Button.MouseButton1Click:Connect(StartPlacementWoodBlock)

Any help please?

I didn’t find any information in your code that says you set the model’s Primary Part. Have you installed it in your model?

EDIT : If you don’t know how to set Primary Part in your model, you can find this parameter in the properties of your model and set it manually.

1 Like

I don’t know what to set as my Prim part.

image

I did that couple minutes ago, it gives me the same error.

image

im pretty sure its Model:SetPrimaryPartCFrame() and make sure its not empty the primarypart

Does the primarypart fall off the map?

I did that I just out those in it

its in replicated storage, I don’t know

Send a screenshot of ur models settings also make sure everything is anchored or the model will fall

If you don’t know how here is this short gif of how to set it:
https://gyazo.com/673f44d96615eeb07af3d3f93ea46e5e

all the models are anchored. idk

yeah I did that

I added the “WoodBlock” model’s prim part to the "WoodBlock"part inside of it

send a screenshot of the properties

properties of what? Model, Part??? Who’s properties?

image

Simply specify the Primary Part. Go to model, click “Primarypart”, then your cursor should turn into a brick and you go into explorer and click the primary part you would like to select. Use a new part and make it sized as big as the whole model and create welds and turn off collisions, transparency to 1. If this doesn’t work then do:

Model.PrimaryPart = <InsertPartNameHere>

You can find more info on primary parts here:

1 Like

let me try all of those right now, I will be back to see if it works.

I understand, and I think I fixed it. so if you look at the script above me the model got deleted before it got to set the primary part