Download src/ServerScriptService/PlotManager.server.lua from algorembrant/TimberWoods: direct link, hf CLI and curl.
- Browser
- Download file 2.55 kB
-
https://huggingface.co/algorembrant/TimberWoods/resolve/main/src/ServerScriptService/PlotManager.server.lua
- Command line
-
hf download hf://algorembrant/TimberWoods/src/ServerScriptService/PlotManager.server.lua
-
curl -L -o PlotManager.server.lua https://huggingface.co/algorembrant/TimberWoods/resolve/main/src/ServerScriptService/PlotManager.server.lua
2.55 kB
| -- src/ServerScriptService/PlotManager.server.lua | |
| local CollectionService = game:GetService("CollectionService") | |
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | |
| local Players = game:GetService("Players") | |
| local PlotConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("PlotConfig")) | |
| local ClaimPlotEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("ClaimPlot") | |
| -- Keeps track of which player owns which plot | |
| local activePlots = {} -- [player.UserId] = plotPart | |
| local function claimPlot(player, targetPlot) | |
| -- Validate requested plot | |
| if not targetPlot or not targetPlot:IsA("BasePart") then return end | |
| if not CollectionService:HasTag(targetPlot, "EmptyPlot") then return end | |
| -- Ensure player doesn't already own a plot | |
| if activePlots[player.UserId] then | |
| print(player.Name .. " already owns a plot.") | |
| return | |
| end | |
| -- Ensure plot isn't already claimed | |
| for _, ownedPlot in pairs(activePlots) do | |
| if ownedPlot == targetPlot then | |
| print("Plot already claimed.") | |
| return | |
| end | |
| end | |
| -- Grant Ownership | |
| activePlots[player.UserId] = targetPlot | |
| -- Change Plot Visuals | |
| targetPlot.BrickColor = BrickColor.new("Bright green") | |
| CollectionService:RemoveTag(targetPlot, "EmptyPlot") | |
| CollectionService:AddTag(targetPlot, "ClaimedPlot") | |
| targetPlot:SetAttribute("OwnerId", player.UserId) | |
| print(player.Name .. " successfully claimed a plot.") | |
| -- Load their Datastore Data onto this plot (Deferred to DatastoreManager) | |
| _G.LoadPlayerData(player, targetPlot) | |
| end | |
| -- Handle Claim Event | |
| ClaimPlotEvent.OnServerEvent:Connect(claimPlot) | |
| -- Cleanup when player leaves | |
| Players.PlayerRemoving:Connect(function(player) | |
| local plot = activePlots[player.UserId] | |
| if plot then | |
| -- Save their data (Deferred to DatastoreManager) | |
| _G.SavePlayerData(player, plot) | |
| -- Reset Plot | |
| plot.BrickColor = BrickColor.new("Dark stone grey") | |
| CollectionService:RemoveTag(plot, "ClaimedPlot") | |
| CollectionService:AddTag(plot, "EmptyPlot") | |
| plot:SetAttribute("OwnerId", nil) | |
| -- Delete all objects on the plot | |
| for _, obj in pairs(plot:GetChildren()) do | |
| if obj:IsA("Model") or obj:IsA("BasePart") then | |
| obj:Destroy() | |
| end | |
| end | |
| activePlots[player.UserId] = nil | |
| end | |
| end) | |