I am not the best with math or model placement and I am wondering if anyone can help me the this model placement system I am working on, right now this is in a local script, I want stuff to be placed server-sided, and I also want to use a module script, I know how to use RemoteEvents, and ModuleScripts just not sure how to convert this type of system though, I also need help with picking the model back up, I don't really know how to go about doing that, but if anyone can help it would be great, also please if you know anyway I can make this shorter, or easier to organize and go through please let me know, this script is in a text button by the way.
-- Priority Varibles
local placement = require(script["Placement (Module)"])
local uis = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local rs = game:GetService("ReplicatedStorage")
local furniture = rs["Furniture"]
local remotes = rs["Remotes"]
local confrimPlacement = remotes["ConfirmPlacement"]
-- Secondary Varibles
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local modelName = tostring(script.Parent:WaitForChild("Name").Text)
--Modle Placement Varibles
local node
local preview
local pp
local selection
local canPlace
local rot = 0
local placing = false
local function previewItem()
if (placing == false) then
return
end
if pp.Position.X+pp.Size.X/2 <= node.Position.X+node.Size.X/2 and pp.Position.Y+pp.Size.Y/2 <= node.Position.Y+node.Size.Y/2 and pp.Position.Z+pp.Size.Z/2 <= node.Position.Z+node.Size.Z/2 and pp.Position.X-pp.Size.X/2 >= node.Position.X-node.Size.X/2 and pp.Position.Y-pp.Size.Y/2 >= node.Position.Y-node.Size.Y/2 and pp.Position.Z-pp.Size.Z/2 >= node.Position.Z-node.Size.Z/2 then
selection.Color3 = Color3.fromRGB(0,155,0)
canPlace = true
else
selection.Color3 = Color3.fromRGB(155,0,0)
canPlace = false
end
preview:SetPrimaryPartCFrame(CFrame.new(mouse.Hit.p+Vector3.new(0,preview.PrimaryPart.Size.Y/2,0))*CFrame.fromEulerAnglesXYZ(0,math.rad(rot),0))
end
local function cancelPlacement()
if (preview) then
placing = false
preview:Destroy()
selection:Destroy()
node = nil
preview = nil
pp = nil
selection = nil
canPlace = nil
rot = 0
end
end
local function startPlacement()
node = workspace["Harbour Studio"]["Node"]
preview = furniture[modelName]:Clone()
preview.Parent = workspace
pp = preview.PrimaryPart
selection = Instance.new("SelectionBox", workspace)
selection.LineThickness = 0.05
selection.Adornee = pp
mouse.TargetFilter = preview
for i,p in next, preview:GetChildren() do
if not (p.Name == "Hitbox") then
p.Transparency = 0.5
p.CanCollide = false
end
end
placing = true
runService.RenderStepped:Connect(previewItem)
end
uis.InputBegan:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.Keyboard) then
if (input.KeyCode == Enum.KeyCode.Q) then
cancelPlacement()
elseif (input.KeyCode == Enum.KeyCode.R) then
if (preview) then
rot = rot +45
preview:SetPrimaryPartCFrame(preview.PrimaryPart.CFrame*CFrame.fromEulerAnglesXYZ(0,math.rad(rot),0))
end
end
elseif (input.UserInputType == Enum.UserInputType.MouseButton1) then
if (preview) and (placing == true) then
print("Placing " .. preview.Name)
local model = preview:Clone()
for i,p in next, model:GetChildren() do
if not (p.Name == "Hitbox") then
p.Transparency = 0
p.CanCollide = true
end
end
model.Parent = workspace["Harbour Studio"]["Furniture"]
end
end
end)
script.Parent.MouseButton1Click:Connect(startPlacement)

1 comment
It's a lot more tough apparently, see https://scriptinghelpers.org/blog/creating-a-furniture-placement-system for help, I myself wouldn't try making this so props to you mate.