Skip to content

Instantly share code, notes, and snippets.

@MajorTal
Created May 31, 2025 12:30
Show Gist options
  • Select an option

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

Select an option

Save MajorTal/a1ff6607717ec6099d7cfb936fcf8208 to your computer and use it in GitHub Desktop.
local tool = script.Parent
local placeRequest = tool:WaitForChild("PlaceRequest")
local Players = game:GetService("Players")
-- Helper function to validate room assignment
local function isWithinAssignedRoom(player, position)
local roomName = player:GetAttribute("Room")
if not roomName then return false end
local room = workspace.PlayerRooms:FindFirstChild(roomName)
if not room then return false end
-- Check if the position is within the room's bounding box
local roomCFrame, roomSize = room:GetBoundingBox()
local relativePosition = roomCFrame:PointToObjectSpace(position)
return math.abs(relativePosition.X) <= roomSize.X / 2
and math.abs(relativePosition.Y) <= roomSize.Y / 2
and math.abs(relativePosition.Z) <= roomSize.Z / 2
end
placeRequest.OnServerEvent:Connect(function(player, position)
if isWithinAssignedRoom(player, position) then
local placedPole = tool.Handle:Clone()
placedPole.Anchored = true
placedPole.CanCollide = true
placedPole.CFrame = CFrame.new(position)
-- Parent it to player's room for neatness
local playerRoom = workspace.PlayerRooms[player:GetAttribute("Room")]
placedPole.Parent = playerRoom
-- Optional: Remove tool from inventory after placement
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