JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Plots | JustPaste.app
about 1 month ago0 views
👨‍💻Programming

Plots

--print("Hello, World!")
local Players = game:GetService("Players")

local plotsFolder = workspace:WaitForChild("Plots")

local playerPlots = {}

-- FIND FREE PLOT
local function getFreePlot()
    for _, plot in ipairs(plotsFolder:GetChildren()) do
        if not plot:GetAttribute("Taken") then
            return plot
        end
    end
    return nil
end

-- PLAYER JOIN
Players.PlayerAdded:Connect(function(player)
    local plot = getFreePlot()
    
    if plot then
        plot:SetAttribute("Taken", true)
        plot:SetAttribute("Owner", player.UserId) -- 🔥 IMPORTANT
        playerPlots[player] = plot
        
        print(player.Name.." got a plot!")
        
        -- TELEPORT PLAYER
        player.CharacterAdded:Connect(function(char)
            local spawn = plot:FindFirstChild("Spawn")
            
            if spawn and spawn:IsA("BasePart") then
                task.wait(1)
                char:MoveTo(spawn.Position + Vector3.new(0,3,0))
            else
                warn("NO SPAWN PART IN PLOT!")
            end
        end)
        
    else
        warn("NO FREE PLOTS!")
    end
end)

-- PLAYER LEAVE
Players.PlayerRemoving:Connect(function(player)
    local plot = playerPlots[player]
    
    if plot then
        plot:SetAttribute("Taken", false)
        plot:SetAttribute("Owner", nil)
        
        -- reset slots
        for _, v in ipairs(plot:GetDescendants()) do
            if v.Name == "Slot" then
                v:SetAttribute("Occupied", false)
            end
 
       end
    end
    
    playerPlots[player] = nil
end)

⚠️Content was pasted as plain text and auto-formatted as a code block. Use the Code Block button in the editor for proper formatting.

← Back to timeline