Advertisement
Sungmingamerpro13

BedPlotHandler (Story Game, ModuleScript)

Jun 4th, 2025
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.25 KB | None | 0 0
  1. local BedPlotHandler = {}
  2.  
  3. BedPlotHandler.AvaliablePlots = game.Workspace.Beds:GetChildren()
  4.  
  5. function BedPlotHandler.GetBed(player)
  6.     for _, bedPlot in pairs(game.Workspace.Beds:GetChildren()) do
  7.         local ownerValue = bedPlot:FindFirstChild("Owner")
  8.        
  9.         if ownerValue and ownerValue.Value == player then
  10.             return bedPlot
  11.         end
  12.     end
  13. end
  14.  
  15. local function UpdateBedGui(plot, Text)
  16.     local OwnernameTag = plot:FindFirstChild("nameTagGui")
  17.    
  18.     OwnernameTag.nameLabel.Text = Text.."'s Bed"
  19. end
  20.  
  21. function BedPlotHandler.namePlot(player)
  22.     local playerPlot = BedPlotHandler.AvaliablePlots[math.random(1,#BedPlotHandler.AvaliablePlots)]
  23.     table.remove(BedPlotHandler.AvaliablePlots, table.find(BedPlotHandler.AvaliablePlots, playerPlot))
  24.    
  25.     local ownerValue = playerPlot:FindFirstChild("Owner") or Instance.new("ObjectValue")
  26.     ownerValue.Name = "Owner"
  27.     ownerValue.Parent = playerPlot
  28.     ownerValue.Value = player
  29.    
  30.     UpdateBedGui(playerPlot, player.DisplayName)
  31. end
  32.  
  33. function BedPlotHandler.NoNamePlot(player)
  34.     local bedPlot = BedPlotHandler.GetBed(player)
  35.    
  36.     if bedPlot then
  37.         bedPlot:FindFirstChild("Owner").Value = nil
  38.         table.insert(BedPlotHandler.AvaliablePlots, bedPlot)
  39.        
  40.         UpdateBedGui(bedPlot, "PlayerName")
  41.     end
  42. end
  43.  
  44. return BedPlotHandler
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement