Creating A Furniture Placement System

These parts of the code are not explained.

Is it ok if anyone can explain to me what the math here does in each piece of code I quoted? I know the operators and constructor functions, I just want to learn why this specific math is done.

Is it possible to place model on other model?

This is really great!

I was having trouble adjusting things so that you could choose furniture by clicking buttons in a GUI (instead of just pressing E). I got the furniture to change, but you can’t place it. Any suggestions? I’m not really much of a scripter, so you might need to dumb it down for me if you have time. :3

Is there a way you could “reconnect” the function?

How would you reconnect the RunService event?

What if I have multiple CanvasParts? How do I make that work?

Agreed. It was pretty hard to follow but I do appreciate the contribution Ego made. I personally was confused and sort of left in the dark.

1 Like

Very nice tutorial, helped me create one of my most recent projects.

I have recently started on another project that also uses a placement system, but works slightly differently. I would want different items of different sizes to be placed on a canvas, that allows rotation in all X, Y and Z components, similar or almost exactly like Plane Crazy’s placement system. This would also allow building items on top of each over (like blocks) and next to each over.

Anyone got an idea of how to perform the right CFrame calculations to determine this?

Just wondering, what is the point in creating a twin on the server in the init placement function ? – Is it to prevent security risks, or does it improve the performance ? Should I be creating twins of all my classes – one on the server and one on the client ?

I think it’s just to make it more modular because that’s his style. That particular section just creates the folder on the server, then sends it to the client when it’s ready. You can split it up however you want as long as the folder exists on the client and the server, and both use the same one. Typically you use “twins” when you have code that the server and client both need so you 're not duplicating code. Also as a side note, the placement server invoke used in this system isn’t actually very secure. It’s relying on the client to tell it there’s no collision, which of course can be exploited.

can you please give me the full script so its easier to input into my game. I put all the code above into a script and it didn’t work
Im not being lazy i’ve just been trying to put something like this into my game forever so please just do it

please help, this is really urgent.
for some reason, it doesn’t load at all when i start it up. i’ve double checked all of my code and i have tried troubleshooting but it hasn’t worked. it doesn’t give any errors, it’s just when i load up the game even if i press F to save 5 times over it will never load, if i press it once twice no matter how many times i press F to save it never loads. i don’t know why, i’m confused, and i really need to know if it’s only me or other people are expericing this problem

even all these years later and it is still a really nice system, gonna rework into something that works for me, but want to ask before i break something, is it possible to have multiple placement planes?

Want to have a multiple floor base that wont be a rectangle/square, so hope this is possible.

How could this be patched? Want to use this, but dont need security risks x D

Unsure what I’ve got wrong, using the multi place, but getting a slight awkward edge where itll do like 0.25 studs instead of 1
ezgif.com-video-to-gif (80)

this is code more or less drag dropped from the demo place, so unsure if it’s how I’ve sized the floor/hitbox?

The floor sizes are all sized by 1, so no decimals. The table has a hitbox/primarypart sized as 4.5x2.25x4.5, so unsure if that’s the issue? Ideally I don’t wanna force every item to have a whole number hitbox, as it’d be awkward with a lot of objects :confused: And if I must, how can I adjust the grid to just do say 0.5 lock? would that resolve everything?

2 Likes

Anyone got ways of server side checks to prevent exploits?

For the previous post you made, did you ever find a solution? If so I’d love to hear it since I’m experiencing a fairly similar issue, for preventing exploits what I do for my game is actually really simple.

After you send a remote event for the server to place down an object, simply have the server run the :CalcPlacement() function the same way that the client does. After doing so the structure will be correctly positioned relative to the canvas

That’s what I tried, however it slightly tweaks the position for some reason, which isn’t ideal

local Indexs, AllCanvases, PlacementParams =
		GetCanvases(PlayersPlotInfo.Interior, FurnitureData.Name, placementInfo.GridInfo or 1)

local VectorRaycast =
workspace:Raycast(placementInfo.CFrame.Position, -placementInfo.CFrame.UpVector * 20, PlacementParams)
if not VectorRaycast or not VectorRaycast.Instance then
	return false, "Invalid position"
end

local FurniturePlacement = AllCanvases[Indexs[VectorRaycast.Instance]]

-- Get rotation
local LookVector = placementInfo.CFrame.LookVector
local StartingRotation = math.deg(math.atan2(-LookVector.Z, LookVector.X))

print(placementInfo.CFrame)

local OriginalCFrame = FurnitureModel:GetPivot() -- Store the original CFrame

local NewCFrame = FurniturePlacement:CalcPlacementCFrame(FurnitureModel, VectorRaycast.Position, math.rad(StartingRotation))
print(NewCFrame)
FurnitureModel:PivotTo(NewCFrame)

VectorRaycast just raycasts down from the given cframe passed to find the canvas to apply to
ezgif.com-video-to-gif (84)

prints return:

  21:30:12.098  1420.75439, 5.50001526, -4160.29688, -1, 0, 0, 0, 1, 0, 0, 0, -1  -  Server - MoveFurniture:48
  21:30:12.098  1420.75439, 5.50001526, -4160.54688, 2.1852959e-06, -9.36116283e-14, 1, 4.37113847e-08, 1, -4.37113918e-08, -1, 4.37113883e-08, 2.1852959e-06

Maybe send the mouse hit position (raycast from mouse) from the client to the server and then use that instead of a already calculated CFrame

Unsure what’s causing this issue with rotating?
ezgif.com-video-to-gif (88)
the model is in a valid position on start, when I go to start rotating, it just moves it off for some reason, and moves back and forth depending on rotation angle

local RaycastDown =
workspace:Raycast(model:GetPivot().Position, -model:GetPivot().UpVector * 20, PlacementParams)
if not RaycastDown or not RaycastDown.Instance then
	return
end

if not Indexs[RaycastDown.Instance] then
	return
end

local FurniturePlacement = AllCanvases[Indexs[RaycastDown.Instance]]

local NewCFrame =
	FurniturePlacement:CalcPlacementCFrame(model, self.OriginalCFrame.Position, math.rad(self.Rotation))
model:PivotTo(NewCFrame)

this uses the same system i have in place for movement, so it shouldn’t be moving when i start rotating anyway

EDIT I believe the offseting is due to different grid locks (placed on a 0.25 grid lock, trying to rotate on 1 grid lock, so it’s lock to with 1 stud. Any way to prevent this from occuring? I could just rotate the model based on self.Rotation but I wanna take into account canvases and if part of the model would be off the canvas. Doing so works, but when I go to server to place, there’s issues around it, as the model gets moved around
ezgif.com-video-to-gif (89)
or on occassion server will block movement (as server detects collisions, due to it trying to move on server) when there aren’t any collisions

2 Likes