Disabling of item placement doesn't work like it should?

So I currently I am making a furniture placement system using Creating A Furniture Placement System - #26 by EgoMoose by EgoMoose and I have modified parts of the client-side script to work with my placement UI. My intention is that once I save the placement, the script will disable the placement and the player is able to edit when he wants to. However, when I try to disable the placement, this error shows up.

From Placement Module
[17:29:39.834 - ReplicatedStorage.Placement:79: attempt to index field 'PrimaryPart' (a nil value)]
From client when the player clicks after the first save
[17:35:39.576 - Players.KawaiiX_Jimin.PlayerGui.LocalScript:18: attempt to index local 'Target' (a nil value)]

Lines where the error occurs

Placement Module

function Placement:CalcPlacementCFrame(model, position, rotation)
	local cf, size = self:CalcCanvas()

local modelSize = CFrame.fromEulerAnglesYXZ(0, rotation, 0) * model.PrimaryPart.Size--error line  that happens after the first save
modelSize = Vector3.new(math.abs(modelSize.x), math.abs(modelSize.y), math.abs(modelSize.z))

local lpos = cf:pointToObjectSpace(position);
local size2 = (size - Vector2.new(modelSize.x, modelSize.z))/2
local x = math.clamp(lpos.x, -size2.x, size2.x);
local y = math.clamp(lpos.y, -size2.y, size2.y);

local g = self.GridUnit
if (g > 0) then
	x = math.sign(x)*((math.abs(x) - math.abs(x) % g) + (size2.x % g))
	y = math.sign(y)*((math.abs(y) - math.abs(y) % g) + (size2.y % g))
end

Client Placement Script

local rStepped = game:GetService("RunService").RenderStepped:Connect(function(dt)--error line which happens after the first save
local cf = placement:CalcPlacementCFrame(model, mouse.Hit.p, rotation)
model:SetPrimaryPartCFrame(cf)
end)

game.ReplicatedStorage.Remotes.disableMouse.OnClientEvent:Connect(function()-- this is the part that breaks the whole system during subsequent edits to the player's placement
rStepped:Disconnect()--stopping the placement
model:Destroy()--removing the model and making it stop following the mouse
end)

I have provided the save file if you would like to understand the problem further
placement.rbxl (62.5 KB)

3 Likes