Skip to content

Instantly share code, notes, and snippets.

@MajorTal
Created May 31, 2025 16:07
Show Gist options
  • Select an option

  • Save MajorTal/a578a80db49d877c97fe50faf19f549b to your computer and use it in GitHub Desktop.

Select an option

Save MajorTal/a578a80db49d877c97fe50faf19f549b to your computer and use it in GitHub Desktop.
local GRID_SIZE = 4 -- Grid snapping size (adjust as needed)
local function snapToGrid(position, gridSize)
return Vector3.new(
math.floor(position.X / gridSize + 0.5) * gridSize,
position.Y,
math.floor(position.Z / gridSize + 0.5) * gridSize
)
end
local function getStackHeight(position, room)
local height = 0
for _, pole in ipairs(room:GetChildren()) do
if pole:IsA("BasePart") then
local polePos = pole.Position
if math.abs(polePos.X - position.X) < 0.1 and math.abs(polePos.Z - position.Z) < 0.1 then
height = math.max(height, polePos.Y + pole.Size.X) -- pole.Size.X (height) per your orientation
end
end
end
return height
end
placeRequest.OnServerEvent:Connect(function(player, position)
if isWithinAssignedRoom(player, position) then
local placedPole = tool.Handle:Clone()
placedPole.Anchored = true
placedPole.CanCollide = true
local snappedPosition = snapToGrid(position, GRID_SIZE)
local playerRoom = workspace.PlayerRooms[player:GetAttribute("Room")]
local currentStackHeight = getStackHeight(snappedPosition, playerRoom)
local poleHeight = placedPole.Size.X -- per your orientation
local finalY = currentStackHeight + (poleHeight / 2)
placedPole.CFrame = CFrame.new(snappedPosition.X, finalY, snappedPosition.Z)
* CFrame.Angles(0, 0, math.rad(90))
placedPole.Parent = playerRoom
tool:Destroy()
else
warn(player.Name .. " tried placing outside their room!")
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment