Created
May 31, 2025 16:10
-
-
Save MajorTal/fa22df5fea4adab5a6beedee7af6535c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local GRID_SIZE = 4 -- Grid snapping size | |
| 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) | |
| end | |
| end | |
| end | |
| return height | |
| end | |
| placeRequest.OnServerEvent:Connect(function(player, position) | |
| print("Received place request from player:", player.Name) | |
| print("Requested position:", position) | |
| if isWithinAssignedRoom(player, position) then | |
| print("Position is within player's assigned room.") | |
| local placedPole = tool.Handle:Clone() | |
| placedPole.Anchored = true | |
| placedPole.CanCollide = true | |
| local snappedPosition = snapToGrid(position, GRID_SIZE) | |
| print("Snapped position:", snappedPosition) | |
| local playerRoomName = player:GetAttribute("Room") | |
| local playerRoom = workspace.PlayerRooms[playerRoomName] | |
| print("Player room identified:", playerRoomName) | |
| local currentStackHeight = getStackHeight(snappedPosition, playerRoom) | |
| print("Calculated current stack height:", currentStackHeight) | |
| local poleHeight = placedPole.Size.X | |
| local finalY = currentStackHeight + (poleHeight / 2) | |
| print("Final pole Y-position:", finalY) | |
| placedPole.CFrame = CFrame.new(snappedPosition.X, finalY, snappedPosition.Z) | |
| * CFrame.Angles(0, 0, math.rad(90)) | |
| placedPole.Parent = playerRoom | |
| print("Pole placed successfully at:", placedPole.Position) | |
| tool:Destroy() | |
| print("Pole tool removed from player.") | |
| else | |
| warn(player.Name .. " tried placing outside their assigned room!") | |
| end | |
| end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment