local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local plotsFolder = Workspace:WaitForChild("Plots")
-- Utility: Get a free plot model from the Plots folder
local function getFreePlot()
local availablePlots = {}
for _, plot in plotsFolder:GetChildren() do
if plot:IsA("Model") then
if not plot:GetAttribute("Occupied") then
table.insert(availablePlots, plot)
end
end
end
if #availablePlots == 0 then
return nil
end
return availablePlots[math.random(1, #availablePlots)]
end
-- Utility: Update the plot's name display
local function updatePlotNameDisplay(plot, playerName)
local template = plot:FindFirstChild("Template")
if not template then
warn("Template model not found in plot: " .. plot.Name)
return
end
local nameDisplayPart = template:FindFirstChild("NameDisplayPart")
if not nameDisplayPart then
warn("NameDisplayPart not found in Template: " .. plot.Name)
return
end
local surfaceGui = nameDisplayPart:FindFirstChildWhichIsA("SurfaceGui")
if not surfaceGui then
warn("SurfaceGui not found in NameDisplayPart: " .. plot.Name)
return
end
local textLabel = surfaceGui:FindFirstChildWhichIsA("TextLabel")
if not textLabel then
warn("TextLabel not found inside SurfaceGui: " .. plot.Name)
return
end
textLabel.Text = playerName
end
-- Utility: Save items in the plot to the player's profile
local function savePlotItems(player, plot)
local profile = _G.Profiles[player]
if not profile then
warn("No profile found for player: " .. player.Name)
return
end
local gunModels = {}
local itemsFolder = plot:FindFirstChild("Items")
if itemsFolder then
for _, item in itemsFolder:GetChildren() do
if item:IsA("Model") and item:GetAttribute("Id") then
local position, orientation
if item.PrimaryPart then
position = item.PrimaryPart.Position
orientation = item.PrimaryPart.Orientation
end
local itemData = {
Id = item:GetAttribute("Id"),
Position = position,
Orientation = orientation,
}
table.insert(gunModels, itemData)
end
end
end
profile.Data.GunModel = gunModels -- Save to GunModel
end
-- Utility: Load items from the player's profile to the plot
local function loadPlotItems(player, plot)
local profile = _G.Profiles[player]
if not profile then
warn("No profile found for player: " .. player.Name)
return
end
local itemsFolder = plot:FindFirstChild("Items")
itemsFolder.Name = "Items"
itemsFolder.Parent = plot
for _, GunID in profile.Data.GunModel do
for _, template in game.ReplicatedStorage:WaitForChild("Weapons"):GetChildren() do
if template:GetAttribute("Id") == GunID then
local clone = template:Clone()
if clone:IsA("Model") and clone.HumanoidRootPart then
local position = GunID.Position
local orientation = GunID.Orientation or Vector3.zero
clone:PivotTo(
CFrame.new(position) * CFrame.fromEulerAnglesXYZ(math.rad(orientation.X), math.rad(orientation.Y), math.rad(orientation.Z))
)
clone.Parent = itemsFolder
end
break
end
end
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
local chosenPlot = getFreePlot()
if not chosenPlot then
warn("No available plots for player: " .. player.Name)
return
end
-- Mark the plot as occupied and store the player's ID
chosenPlot:SetAttribute("Occupied", true)
chosenPlot:SetAttribute("Id", player.UserId)
updatePlotNameDisplay(chosenPlot, player.Name)
-- Load items from the player's profile
loadPlotItems(player, chosenPlot)
-- Try to find a base part to attach the display to
local basePart = chosenPlot:FindFirstChildWhichIsA("BasePart")
if not basePart then
warn("No BasePart found in plot: " .. chosenPlot.Name)
return
end
-- Create BillboardGui directly on the plot
local billboard = Instance.new("BillboardGui")
billboard.Name = "PlayerProfile"
billboard.Size = UDim2.new(0, 250, 0, 130)
billboard.StudsOffset = Vector3.new(0, 6, 0)
billboard.AlwaysOnTop = true
billboard.MaxDistance = 250
billboard.Adornee = basePart
billboard.Parent = basePart
-- Avatar headshot
local imageLabel = Instance.new("ImageLabel")
imageLabel.Size = UDim2.new(0, 120, 0, 120)
imageLabel.Position = UDim2.new(0, 5, 0, 5)
imageLabel.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
imageLabel.BackgroundTransparency = 0
imageLabel.Image = "https://www.roblox.com/headshot-thumbnail/image?userId=" .. player.UserId .. "&width=100&height=100&format=png"
imageLabel.BorderSizePixel = 0
imageLabel.Parent = billboard
-- Make the image circular
local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(1, 0)
corner.Parent = imageLabel
end)
Players.PlayerRemoving:Connect(function(player)
for _, plot in plotsFolder:GetChildren() do
if plot:GetAttribute("Id") == player.UserId then
-- Save items before clearing the plot
savePlotItems(player, plot)
plot:SetAttribute("Occupied", false)
plot:SetAttribute("Id", nil)
-- Optionally clear items from the plot
local itemsFolder = plot:FindFirstChild("Items")
if itemsFolder then
itemsFolder:ClearAllChildren()
end
break
end
end
end)
This is the plothandler script