Cakey3101

GAG Plot Service

Aug 23rd, 2025
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | Source Code | 0 0
  1. local Workspace = game:GetService("Workspace")
  2.  
  3. local PlotsFolder = Workspace:WaitForChild("Plots")
  4.  
  5. local FORCE_ASSIGN = false
  6. local FORCED_PLOT_NAME = "Plot1"
  7.  
  8. local PlotService = {}
  9. local PlotOwners = {}
  10.  
  11. function PlotService.GetPlotOwners()
  12.     return PlotOwners
  13. end
  14.  
  15. function PlotService.GetPlot(Player: Player)
  16.     for Plot, Owner in pairs(PlotOwners) do
  17.         if Owner == Player then
  18.             return Plot
  19.         end
  20.     end
  21.    
  22.     return nil
  23. end
  24.  
  25. function PlotService.AssignPlot(Player: Player)
  26.     if FORCE_ASSIGN then
  27.         local ForcedPlot = PlotsFolder:FindFirstChild(FORCED_PLOT_NAME)
  28.        
  29.         if ForcedPlot then
  30.             for P, Owner in pairs(PlotOwners) do
  31.                 if Owner == Player or P == ForcedPlot then
  32.                     PlotService.FreePlot(Owner)
  33.                 end
  34.             end
  35.            
  36.             PlotOwners[ForcedPlot] = Player
  37.            
  38.             local OwnerTag = ForcedPlot:FindFirstChild("Owner") or Instance.new("ObjectValue")
  39.             OwnerTag.Name = "Owner"
  40.             OwnerTag.Value  = Player
  41.             OwnerTag.Parent = ForcedPlot
  42.            
  43.             local SignGui = ForcedPlot:FindFirstChild("Sign"):FindFirstChild("GuiPart") and ForcedPlot.Sign.GuiPart:FindFirstChildOfClass("SurfaceGui")
  44.             local Label = SignGui and SignGui:FindFirstChildOfClass("TextLabel")
  45.  
  46.             if Label then
  47.                 Label.Text = `{Player.Name}'s Garden`
  48.             end
  49.            
  50.             if Player.Character then
  51.                 PlotService.TeleportToPlot(Player)
  52.             end
  53.  
  54.             Player.CharacterAdded:Connect(function()
  55.                 PlotService.TeleportToPlot(Player)
  56.             end)
  57.            
  58.             return ForcedPlot
  59.         end
  60.     end
  61.    
  62.     for _, Plot in ipairs(PlotsFolder:GetChildren()) do
  63.         if not PlotOwners[Plot] then
  64.             PlotOwners[Plot] = Player
  65.             local OwnerTag = Plot:FindFirstChild("Owner") or Instance.new("ObjectValue")
  66.             OwnerTag.Name = "Owner"
  67.             OwnerTag.Value  = Player
  68.             OwnerTag.Parent = Plot
  69.  
  70.             local SignGui = Plot:FindFirstChild("Sign"):FindFirstChild("GuiPart") and Plot.Sign.GuiPart:FindFirstChildOfClass("SurfaceGui")
  71.             local Label = SignGui and SignGui:FindFirstChildOfClass("TextLabel")
  72.  
  73.             if Label then
  74.                 Label.Text = `{Player.Name}'s Garden`
  75.             end
  76.  
  77.             if Player.Character then
  78.                 PlotService.TeleportToPlot(Player)
  79.             end
  80.  
  81.             Player.CharacterAdded:Connect(function()
  82.                 PlotService.TeleportToPlot(Player)
  83.             end)
  84.  
  85.             return Plot
  86.         end
  87.     end
  88.  
  89.     return nil
  90. end
  91.  
  92. function PlotService.TeleportToPlot(Player: Player)
  93.     local Plot = PlotService.GetPlot(Player)
  94.    
  95.     if Plot then
  96.         local SpawnLocation = Plot:FindFirstChild("Spawn")
  97.        
  98.         if SpawnLocation and Player.Character.PrimaryPart then
  99.             Player.Character:PivotTo(SpawnLocation.CFrame)
  100.         end
  101.     end
  102. end
  103.  
  104. function PlotService.FreePlot(Player: Player)
  105.     for Plot, Owner in pairs(PlotOwners) do
  106.         if Owner == Player then
  107.             PlotOwners[Plot] = nil
  108.             local OwnerTag = Plot:FindFirstChild("Owner")
  109.            
  110.             if OwnerTag then
  111.                 OwnerTag:Destroy()
  112.             end
  113.            
  114.             local SignGui = Plot:FindFirstChild("Sign"):FindFirstChild("GuiPart") and Plot.Sign.GuiPart:FindFirstChildOfClass("SurfaceGui")
  115.             local Label = SignGui and SignGui:FindFirstChildOfClass("TextLabel")
  116.  
  117.             if Label then
  118.                 Label.Text = `Empty Garden`
  119.             end
  120.            
  121.             return true
  122.         end
  123.     end
  124.    
  125.     return false
  126. end
  127.  
  128. return PlotService
Advertisement
Add Comment
Please, Sign In to add comment