Help System of plot

Hello everyone, I am looking to see if someone knows a plot system or plot system as you know it, and you are looking for some that are assigned automatically when entering the game if someone knows it or knew how to do it and told me I would appreciate it very much.
image
This are the plot y have.

2 Likes

You can assign a plot multiple ways, but one way would be to have an IntValue inside the plot Part and set the value to the UserId when they enter of the first empty plot and remove their name when they leave. Here’s an example:

Preferably in a script in ServerScriptService

local plots = workspace.Plots -- I'm assuming Plots folder is in workspace

game.Players.PlayerAdded:Connect(function (player)
   for _,plot in pairs(plots:GetChildren()) do -- iterate through plots
      if plot:FindFirstChild("OwnerId") then -- a value exists, does anyone own it?
         if plot.OwnerId.Value == 0 then -- we found an empty plot
            plot.OwnerId.Value = player.UserId -- new owner now
            break -- no need to continue iterating we're done here
         end
      else -- value doesn't exist in this plot create and make owner
         local newValue = Instance.new("IntValue", plot) -- create new value into plot
         newValue.Name = "OwnerId" -- name the value
         newValue.Value = player.UserId -- new owner now
         break -- once again, no need to continue let's break
      end
   end
end)

-- when player leaves, we need to remove their ownership from game
-- we will iterate through plots and find the one they own and remove them from it
game.Players.PlayerRemoving:Connect(function (player)
   for _,plot in pairs(plots:GetChildren()) do -- iterate through plots
      if plot:FindFirstChild("OwnerId") then -- a value exists in this plot, who's is it?
         if plot.OwnerId.Value == player.UserId then -- if the owner's id is on plot...
            plot.OwnerId.Value = 0 -- now the owner field is empty
         end
      end
   end)
end)

Also important to note that the script adds the IntValues for you so you don’t have to make do those intValues manually simply insert the script into the game and it’ll run for you.

Detect Owner

-- returns nil if no owner
-- returns 'player' instance if owner exists
function who_is_owner(plot) -- let's say you want to see if plot has an owner
   if plot:FindFirstChild("OwnerId") and plot.OwnerId.Value~=0 then
      return game.Players:GetPlayerByUserId(plot.OwnerId.Value)
   end
   return nil
end
1 Like

So i need to put the first script in server script service in a script and put a in value in everry plot name it userid and the last script?

Nope. Simply insert the script and hit Play see inside the plots to check which one is yours. The script will iterate through the plots on entry and find the first empty plot and create the IntValue if it doesn’t already exist, which means no need to copy and paste the IntValue yourself.

I added comments to each line of the script so you can read what each step does. Highly recommend reading it.

if i understeend correctly the second script i need to put it into the plots? all the script in each one? (Sorry for much questions but im not much good in scripting)

No it’s cool no worries. So the second script can go anywhere you want. It’s just an example of how you determine who is the owner if anyone. You can put it inside of the build script to check if they’re owner before placing, or I recommend inside a ModuleScript in ReplicatedStorage so taht both clients and server can run the function. That’s up to you from there.

1 Like

Thanks you so much the script funtion correctly do you know how to put the owner text i mean i have the text is into the plots

Here’s a hint using the second function I gave you:

local name = who_is_owner().Name -- may error, or may not error this for you to fix

I need to put that script in the text gui?