First script: assigns player an id through attributes
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MAX_PLOTS = 10
local assignPlotEvent = ReplicatedStorage:WaitForChild("AssignPlotIDEvent")
local assignedPlots = {}
local playerPlots = {}
local function findAvailablePlot()
for i = 1, MAX_PLOTS do
if not assignedPlots[i] then
return i
end
end
return nil
end
local function onPlayerAdded(player)
if playerPlots[player] then
assignPlotEvent:FireClient(player, playerPlots[player])
print(player.Name .. " already has Plot ID: " .. playerPlots[player])
return
end
local assignedPlotId = findAvailablePlot()
if assignedPlotId then
print("Assigning Plot ID " .. assignedPlotId .. " to player " .. player.Name)
assignedPlots[assignedPlotId] = player
playerPlots[player] = assignedPlotId
player:SetAttribute("PlotID", assignedPlotId)
assignPlotEvent:FireClient(player, assignedPlotId)
end
end
local function onPlayerRemoving(player)
local plotId = playerPlots[player]
if plotId then
print("Releasing Plot ID " .. plotId .. " from player " .. player.Name)
assignedPlots[plotId] = nil
playerPlots[player] = nil
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAdded, player)
end
print("PlotAssigner Booted :P")
Second script: determines if plotID matches with the name of a part in a folder in Workspace and tries to turn off the CanCollide property if it matches.