Claimable Bed System

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)

sure

that taking longer for him, also prob he dont want to close main place then go another place

thats exactly what my bed set up looks like but the code isnt working for me im getting an output error on the character or something.

He can still have studio open it just will open another studio tab

the if statement wrong, use my script better

okay let me see if i can modify it.

Classic Baseplate.rbxl (49.2 KB)
also this is the place bc u cant import the file, u can check it

dk but ppl pc cant handle 2 studio bc lag

what’s the difference of you sending him a file of your place then???

alright so almost got it working just one more request with this script are we able to make it so that it stays the players permanent bed? because thats what im trying to go for.

local billboard = bed:FindFirstChild("BillboardGui")
local claimSeat = bed:FindFirstChild("ClaimSeat") -- seat part
local ownerName = nil

local function claimBed(player)
	if not ownerName then
		ownerName = player.Name
		player:SetAttribute("IsOnBed", true) -- set player is on bed to true
		if billboard then
			billboard.TextLabel.Text = ownerName
			billboard.Enabled = true
		end
	end
end

local function releaseBed(player)
	if ownerName and ownerName == player.Name then
		ownerName = nil
		player:SetAttribute("IsOnBed", nil) -- set to nil if release bed
		if billboard then
			billboard.TextLabel.Text = ""
			billboard.Enabled = false
		end
	end
end

claimSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local Humanoid = claimSeat.Occupant
	if not Humanoid then
		return
	end

	local Character = Humanoid.Parent
	local player = game.Players:GetPlayerFromCharacter(Character)
	if player then
		if not ownerName and not player:GetAttribute("IsOnBed") then
			claimBed(player)
		end
	end

	Humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
		releaseBed(player)
	end)
end)

u didnt know diffrient of rbxm and rblx?

1 Like

that easy, just set jumppower to 0

1 Like

that script i just posted is the current edited one.

1 Like

yeah i remove some useless part

1 Like

i want it to be so when they jump off their bed its their “claimed” bed and they can go back to it at any time and no one can take it and they cant claim another.

1 Like

if you can do that for me ill add you and send u 500 robux.

1 Like

i do it already? u didnt read the script?

1 Like

no need, helping ppl with me is fine already

2 Likes

You shouldn’t need to pay people to help you on the devforum it 100% FREE

1 Like