Skip to content

Instantly share code, notes, and snippets.

@MajorTal
Created June 1, 2025 16:00
Show Gist options
  • Save MajorTal/adc42b45cec0e6092851369d357c4dcf to your computer and use it in GitHub Desktop.
Save MajorTal/adc42b45cec0e6092851369d357c4dcf to your computer and use it in GitHub Desktop.
local function restackPolesAtPosition(deletedPolePosition, room)
local polesAtPos = {}
-- Find poles at same X,Z position
for _, pole in ipairs(room:GetChildren()) do
if pole:IsA("BasePart") then
if math.abs(pole.Position.X - deletedPolePosition.X) < 0.1 and math.abs(pole.Position.Z - deletedPolePosition.Z) < 0.1 then
table.insert(polesAtPos, pole)
end
end
end
-- Sort poles by height (Y-position), ascending
table.sort(polesAtPos, function(a, b)
return a.Position.Y < b.Position.Y
end)
-- Get the precise pole height from your actual pole object
local actualPoleHeight = polesAtPos[1] and polesAtPos[1].Size.X or 4
-- Start stacking exactly on the room surface
local roomTopSurfaceY = room.Position.Y + (room.Size.Y / 2)
for index, pole in ipairs(polesAtPos) do
local newY = roomTopSurfaceY + actualPoleHeight * (index - 0.5)
pole.CFrame = CFrame.new(deletedPolePosition.X, newY, deletedPolePosition.Z)
* CFrame.Angles(0, 0, math.rad(90))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment