Need Help with my code[NOT SOLVED]

I am making a placement system but I came across 2 problems.

I have made a Module Script in replicated storage called “PlacementValidator”

first problem is how can I set a max hight?

for example, I would like to place 3 objects each on top and after that, I can’t

Second problem how can I make it can’t collide with other objects?

I have no clue how to make it check if it’s colliding anything

https://streamable.com/0gd3t5

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")

local modules = ReplicatedStorage:WaitForChild("Modules")
local gridSize = modules:WaitForChild("GridSize").Value

local placedProducts = Workspace:WaitForChild("PlacedProducts")
local whitelistedToPlace = Workspace:WaitForChild("WhitelistedToPlace")


local function isValid(cframe: CFrame, size: Vector3): boolean
	local overlapParams = OverlapParams.new()
	overlapParams.FilterDescendantsInstances = {placedProducts:GetChildren(), whitelistedToPlace:GetChildren()}
	overlapParams.FilterType = Enum.RaycastFilterType.Include

	if Workspace:GetPartBoundsInBox(cframe, size, overlapParams)[1] then
		return true
	else
		return false
	end
end

local function snapToGrid(position: Vector3): Vector3
	return Vector3.new(
		math.round(position.X / gridSize) * gridSize,
		position.Y,
		math.round(position.Z / gridSize) * gridSize)
end

local placementValidator = {
	IsValid = isValid,
	SnapToGrid = snapToGrid
}

return placementValidator

still not solved it

isn’t the isValid function making sure objects can’t collide and can’t you just add a limit on the Y axis to set a max height

that’s what I have tried to do, but it won’t work

how are using isValid and snapToGrid?

what do you mean?, is valid needs to return true if valid and false if not,

snap to grid is used when its valid and I am checking for valid space to place

I meant how ur calling the functions?

its been called from module script that maintain the placement system in replicated storage:

local function onRenderStepped()
	mousePosition = Get3dMousePosition(raycastParams)
	if snapToGrid then mousePosition = PlacementValidator.SnapToGrid(mousePosition) end

	local cframe = CFrame.new(mousePosition) * CFrame.fromEulerAnglesYXZ(0, math.rad(currentAngle), 0)
	local size = if itemClone:IsA("Model") then itemClone:GetExtentsSize() else itemClone.Size
	local isValid = PlacementValidator.IsValid(cframe, size)

	boxOutline.SurfaceColor3 = if isValid then VALID_COLOR else INVALID_COLOR
	itemClone:PivotTo(cframe)
end

@BrickBattlerOfTheDay

I don’t know why it’s not working, I hope you understand that. i need to disable the collision between objects. as you said I have tried include that folder “WhitelistedToPlace” and “PlacedProducts”

PlacedProducts is the folder when the object is placed in its his parent(workspace).
WhitelistedToPlace is the folder that includes the placeable objects like shelf or something in my case that floor platform

I don’t know why it’s not working, I hope you understand that. i need to disable the collision between objects. as you said I have tried include that folder “WhitelistedToPlace” and “PlacedProducts”

PlacedProducts is the folder when the object is placed in its his parent(workspace).
WhitelistedToPlace is the folder that includes the placeable objects like shelf or something in my case that floor platform

Does anyone know how to fix it? :pray:

still not solved i am stuck please if someone can help me :pray:

i’m unable to write code for you right now but I can hopefully push you in the right direction

for the height limit, since you want specifically 3 objects to be placed on one another regardless of size, whenever you place an object, detect if it’s on top of 3 or more other objects, and if so, cancel the function.

you can use the same logic for collision, using WorldRoot:GetPartsInPart() the server can check if the part is in another object’s hitbox.

didn’t work i tried, any other solutions?

my problem isn’t solved yet, i was trying to make it work for whole 2 weeks and I still didn’t found solution

https://streamable.com/i8gglr

i am 100% sure that its need to be changed in the PlacementValidator script, because its his main goal. to validate a placement, that means that it needs to check if any objects colliding and to set max height

but I can’t figure it out how to make it work

I’ve look at more than a few of these for direction: This one clearly stands out after an update.
You may want to take a look at how this was put together…

ROBLOX Placement System Tutorial
Placement System - Rotate and Y axis included

You can skip right to the Rotate and Y axis included link.
Instantly impressive.

in his system i still can place inside of other objects:

image

about the max height, I didn’t find anything related to it,

can you show me where?

@2112Jay I have checked it and its not helping me, not the first problem and not the second one

Hold the object in front of the other; it becomes solid, then it will allow it to be stacked.
He has a bit of play between solid and non-collectible, depending on where you’re holding it at the moment. Once solid, move upwards. Figure out how he’s doing that part when they are acting as solids. Your answer is right there … revere engineer that.

I also found it impressive how far you can place objects away from yourself and how you can change your view angle (not the object) while holding an object. Good stuff, a lot to learn for that one.

i have tried, still didn’t solved my problem…

07.12.24 UPDATE:

I tried watching tutorials and making it work but still didn’t succeed.

please hopefully someone can help me…

updated video:

https://streamable.com/0gd3t5

only have a clue for this one

you could possibly have some sort of invisible part, and upon the player trying to place anything,
you check if any of the chosen building parts are touching the height part, if they are, cancel the placement

Region3 or some variant, it will loop through all of the colliding parts, maybe check if the part is of parent of model

local getTouchingParts = game.Workspace:FindPartsInRegion3() -- gets table of all parts in region3

for i,v in pairs(getTouchingParts) do --loops through the table
	print(v.Name) -- prints name of the part in the loop right now
    --
if v.Parent.Name == "Table" then
--not valid
end)
        

end 

And for the height limit you could probably solve something like that also using region3 and Y data