Cannot Claim More Than One Building Area

Could you possibly provide me with some code to work with?

1 Like

Yes let me quickly write the basic idea of how it will work.

1 Like

:white_check_mark: Alrighty, see ya when it’s ready. :slightly_smiling_face:

1 Like

If you are using OOP then you can make something like this

local padModule = require(someModuleHere)
local somePart = workspace.SomePart

local padHandler = padModule.new()

somePart.Touched:Connect(function() -- get the player using hit and add debounce
  padHandler:AssignPad(plr)
end)

-- The script below will be in the module
function module:AssignPad(plr)
  if self.AssignedPads[plr.Name] then
      return
  end

  self.AssignedPads[plr.Name] = plr
   -- Do more stuff here
end

now you can check if the player is in the table and if the player is not in the table then assign them with a new pad

I’m really new to scripting, can you elaborate on what OOP is?

1 Like

I will share my code with you two and see if there is a way y’all could help.

You can refer to @LifeDigger 's reply to know what it is in detail

Here is a short explanation: Object Oriented Programming or OOP for short is basically creating Instances and giving them custom properties using metatables and metamethods (refer to LifeDigger’s post for examples and replies)

Alright, if I share the piece(s) of code with you, could you make an attempt to help?

1 Like

Please do share I can try my best to help

local players = game:GetService(“Players”)
local replicatedStorage = game:GetService(“ReplicatedStorage”)

local claims = workspace:WaitForChild("[Claim Private Areas]")
local areas = workspace:WaitForChild("[Private Building Areas]")

local function newClaim(claim)
local area = areas:WaitForChild(claim.Name)
local owner = nil

claim.Touched:Connect(function(part)
	if not owner then
		local player = players:GetPlayerFromCharacter(part.Parent)

		if player then
			owner = player
			local permissions = require(area["[Permissions]"])
			
			permissions[1] = {
				Type = "Player",
				PlayerId = player.UserId,
				PlayerName = player.Name
			}
			
			replicatedStorage.UpdatePermissions:FireAllClients(area, player)
			
			claim.Color = Color3.new(1, 0, 0)
			player.AncestryChanged:Wait()
			owner = nil
			claim.Color = Color3.new(0, 1, 0)
			
			replicatedStorage.UpdatePermissions:FireAllClients(area, nil)
		end
	end
end)

end

for i, claim in pairs(claims:GetChildren()) do
coroutine.wrap(newClaim)(claim)
end

claims.ChildAdded:Connect(newClaim)

Please do share the code I can try my best to help

You can store a StringValue inside of the pad holding the occpuant. If the player that touched the pad owns it than you can return else StringValue.Value = hit.Parent.Name.

local players = game:GetService(“Players”)
local replicatedStorage = game:GetService(“ReplicatedStorage”)

local claims = workspace:WaitForChild("[Claim Private Areas]")
local areas = workspace:WaitForChild("[Private Building Areas]")

local function newClaim(claim)
local area = areas:WaitForChild(claim.Name)
local owner = nil

claim.Touched:Connect(function(part)
	if not owner then
		local player = players:GetPlayerFromCharacter(part.Parent)
                if player:FindFirstChild("OwnsPad") then
                     return
                end
                local ownerTag = Instance.new("BoolValue")
                ownerTag.Name = "OwnsPad"
                ownerTag.Parent = plr
		if player then
			owner = player
			local permissions = require(area["[Permissions]"])
			
			permissions[1] = {
				Type = "Player",
				PlayerId = player.UserId,
				PlayerName = player.Name
			}
			
			replicatedStorage.UpdatePermissions:FireAllClients(area, player)
			
			claim.Color = Color3.new(1, 0, 0)
			player.AncestryChanged:Wait()
			owner = nil
			claim.Color = Color3.new(0, 1, 0)
			
			replicatedStorage.UpdatePermissions:FireAllClients(area, nil)
		end
	end
end)
end

for i, claim in pairs(claims:GetChildren()) do
coroutine.wrap(newClaim)(claim)
end

claims.ChildAdded:Connect(newClaim)

Try this code this should work (make sure to delete the owner tag from the player once the plot is not owned by the player anymore)

What do you mean delete the owner tag?

the code also does not work unfortunately.

Hello! Where would I add the else StringValue.Value = hit.Parent.Name . in the code?

here I create a bool value inside the player which tells us that the player owns a pad so you need to delete it once the player does not own the plot anymore

I’m going to make an attempt to use the other guys small code, could you help me with his?
else StringValue.Value = hit.Parent.Name .
Where would I place it in the code?

I see a lot of complicated methods, but an easy way to do this is to use the CollectionService, already developed by Roblox. You can just add a Collection Service Tag, using the player’s name and the tag, as follows:

 local CollectionService = game:GetService("CollectionService")        
 CollectionService:AddTag(PAD,player.Name.."_padownership")

(PAD is your object, block, model, any Roblox Instance can be tagged…)
and then just check if they already have a pad tagged in existence by doing this

 local owned_items = CollectionService:GetTagged(player.Name.."_padownership") 

which will return an array of anything tagged or nil if nothing exists. Easy, simple, elegant.

You might even add a tag named “Owned” or “Locked” so other players can’t try taking ownership by doing this check:

 local lockflag = CollectionService:HasTag("LOCKED")

You can even check for these tags across the Streaming Filter (both local client scripts and server scripts can check for these tags which makes them VERY powerful and useful!)