Hello, I am in need of assistance so that you cannot claim more than one private building area.
The pads are what indicates if you have access to place inside of the transparent blocks area. I am trying to make it so you cannot claim more than one pad, could anyone help me?
So there a few different ways you can achieve this but the way I would do it is have a table in a script and if the player stands on a pad to claim a building area then it looks through the table and using a if statement make it so if the player username who touched the pad is not in the table then let them claim the pad and add there username to the table but if it is in the table then just do not run the claiming script and either do nothing or make some type of UI come up saying they can’t clam any more then one or something.
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
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)
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
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)
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