hey takanashi is there a way you could help me design this code? its almost finished the only problem with it is players who claimed a bed can claim another i dont know what the problem with it is.
local billboard = bed:FindFirstChild("BillboardGui")
local claimSeat = bed:FindFirstChild("ClaimSeat")
local claimedValue = Instance.new("BoolValue")
claimedValue.Name = "Claimed"
claimedValue.Parent = bed
local ownerName = nil
local claimedBedSeat = nil
local function claimBed(player)
if not claimedValue.Value then
claimedValue.Value = true
ownerName = player.Name
if billboard then
billboard.TextLabel.Text = ownerName
end
-- Disable other beds for the owner
for _, otherBed in ipairs(game.Workspace.Beds:GetChildren()) do
if otherBed:IsA("Model") and otherBed ~= bed then
local otherClaimedValue = otherBed:FindFirstChild("Claimed")
if otherClaimedValue and otherClaimedValue.Value and ownerName == player.Name then
local otherClaimSeat = otherBed:FindFirstChild("ClaimSeat")
if otherClaimSeat then
otherClaimSeat.Disabled = true
end
end
end
end
-- Enable the seat for this bed so that the player can sit on it after claiming
if claimSeat then
claimSeat.Disabled = false
claimedBedSeat = claimSeat
end
end
end
local function releaseBed()
if claimedValue.Value then
claimedValue.Value = false
ownerName = nil
if billboard then
billboard.TextLabel.Text = ""
end
-- Enable all beds for the owner
for _, otherBed in ipairs(game.Workspace.Beds:GetChildren()) do
if otherBed:IsA("Model") then
local otherClaimedValue = otherBed:FindFirstChild("Claimed")
if otherClaimedValue and otherClaimedValue.Value then
local otherClaimSeat = otherBed:FindFirstChild("ClaimSeat")
if otherClaimSeat then
otherClaimSeat.Disabled = false
end
end
end
end
-- Disable the claimed bed seat as the player has released the bed
if claimedBedSeat then
claimedBedSeat.Disabled = true
claimedBedSeat = nil
end
end
end
claimSeat.Touched:Connect(function(hit)
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
if not claimedValue.Value and not player:IsAncestorOf(bed) then
claimBed(player)
elseif claimedValue.Value and player:IsAncestorOf(bed) and ownerName == player.Name then
releaseBed()
elseif claimedValue.Value and not player:IsAncestorOf(bed) then
print("You already have a claimed bed.")
end
end
end)