Right now I'm working on a furniture placement System. I have a folder in ReplicatedStorage that contains my furniture. My code was originally written to work with a single part, but now, I'm trying to change it so that I can pull an entire model out of replicated storage and drag it to wherever I would like.

Here's all my initial set up information, although the error comes in the next snippet.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = ReplicatedStorage:WaitForChild("PlaceStructure")
local Structures = ReplicatedStorage:WaitForChild("Structures")

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local StructureFrame = script.Parent.StructureFrame

local char = player.Character or player.Character:Wait()
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")

local mouse = player:getMouse()

local preciseMode = false
local gridAmount = 1
local yBuildingOffset = 5
local maxPlacingDistance = 20
local rKeyIsPressed = false
local placingStructure = false -- used for debounce

This is where I begin to have trouble. I placed in these print statements to figure out where my code runs until, although it never makes it to the second one.

for _, structureButton in pairs(StructureFrame:GetChildren()) do
	if structureButton:IsA("TextButton") then
		structureButton.MouseButton1Up:Connect(function()
			
		StructureFrame.Visible = false
		local yOrientation = 0
		local goodToPlace = false
		local placedStructure
			
		if placingStructure == false then
			placingStructure = true
				
			local clientStructure = Structures:FindFirstChild(structureButton.Name):Clone()
			clientStructure.PrimaryPart = clientStructure.primpart
			local primpart = clientStructure.PrimaryPart
			primpart.CanCollide = false
			primpart.Transparency = .3
			primpart.Parent = game.Workspace
			primpart.SelectionBox.Visible = true
			print(1) -- prints this to the output
				
				
			local startingCFrame = CFrame.new(0, -2, -15)
		    clientStructure:SetPrimaryPartCFrame(HumanoidRootPart.CFrame:ToWorldSpace(startingCFrame))
			print(2) -- does not make it to this print statment

I have the following error in my output as well:

**12:36:52.221 - Model:SetPrimaryCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this. **

This is where I'm lost, as I am setting the primary part in the model, but also at the top of my script. Any advice or where to go from here?

I would also like to add that the primary part of the furniture piece makes its way into the workspace, but doesn't move. It just sits in the middle of the baseplate .

2 comments

0

CFrame

0

Just use Model.Part.CFrame