Alright everyone, I am trying to make a bed system like cracky4’s break in and just cant seem to get it right ive tried a bunch of stuff and dont know where to start. To give context im looking for a script where people and sit on a bed and claim it, once they claim it they cant claim another bed and no one can claim their bed. Thanks so much for the help in advance if anyone is able to solve this ill send 500 robux to whoever can help me fix this script.
Why not make a boolean value in the player and if it is true when they claim a bed then it won’t claim. instead of player sitting on the bed why not use proximity prompt to claim it. and when they do claim it do :Destroy to the proximity prompt that way its unclaimable.
i tried that already but it seems like even after the other players can still sit in my claimed seat even if they claim it by laying down.
ok, I asked a question on the devforum not too long ago maybe it would help
Here is how:
- Detect when a player sit on the bed then add a attribute in the bed then set it to true
- Set inside player a attribute and set it to true too
You can do this to check player
if player:GetAttribute("SitOnBed") == true and bed:GetAttribute("PlayerSitOnBed") == Player.Name then
Hope this can help u tho
using that script i was able to modify my script in the bed to come up with something like this
local billboard = bed:FindFirstChild("BillboardGui")
local claimSeat = bed:FindFirstChild("ClaimSeat")
local ownerName = nil
local function claimBed(player)
if not ownerName then
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 otherOwnerName = otherBed:FindFirstChild("OwnerName")
if otherOwnerName and otherOwnerName.Value == ownerName then
local otherClaimSeat = otherBed:FindFirstChild("ClaimSeat")
if otherClaimSeat then
otherClaimSeat.Disabled = true
end
end
end
end
end
end
local function releaseBed()
if ownerName then
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 otherOwnerName = otherBed:FindFirstChild("OwnerName")
if otherOwnerName and otherOwnerName.Value == ownerName then
local otherClaimSeat = otherBed:FindFirstChild("ClaimSeat")
if otherClaimSeat then
otherClaimSeat.Disabled = false
end
end
end
end
end
end
claimSeat.Touched:Connect(function(hit)
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
if not ownerName and not player:IsAncestorOf(bed) then
claimBed(player)
elseif ownerName == player.Name and player:IsAncestorOf(bed) then
releaseBed()
end
end
end)
right now i was able to make a script like this
local billboard = bed:FindFirstChild("OwnerBillboard")
local claimSeat = bed:FindFirstChild("ClaimSeat")
local ownerName = nil
local function claimBed(player)
if not ownerName then
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 otherOwnerName = otherBed:FindFirstChild("OwnerName")
if otherOwnerName and otherOwnerName.Value == ownerName then
local otherClaimSeat = otherBed:FindFirstChild("ClaimSeat")
if otherClaimSeat then
otherClaimSeat.Disabled = true
end
end
end
end
end
end
local function releaseBed()
if ownerName then
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 otherOwnerName = otherBed:FindFirstChild("OwnerName")
if otherOwnerName and otherOwnerName.Value == ownerName then
local otherClaimSeat = otherBed:FindFirstChild("ClaimSeat")
if otherClaimSeat then
otherClaimSeat.Disabled = false
end
end
end
end
end
end
claimSeat.Touched:Connect(function(hit)
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
if not ownerName and not player:IsAncestorOf(bed) then
claimBed(player)
elseif ownerName == player.Name and player:IsAncestorOf(bed) then
releaseBed()
end
end
end)
And i was wondering if anyone can help modfiy it, right now theres a billboard in the bed and a seat in the bed and when you lay down your name comes up the only 2 problems are other people can claim your already claimed bed and you can claim other beds still.
use a bool value in the player to determine if he already claimed a bed by setting it to true
local claim = Instance.New("BoolValue")
claim.Name = "Claim"
claim.Parent = Player
suggestion create a folder to put the boolvalue in by using instance.new
alright let me try that out it might work considering the fact that the script is checking if a bed is claimed.
here is the script i fix for u, if u dont understand anything u can ask me
local bed = script.Parent -- insert your bed here
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
end
end
end
local function releaseBed(player)
if ownerName then
ownerName = nil
player:SetAttribute("IsOnBed", nil) -- set to nil if release bed
if billboard then
billboard.TextLabel.Text = ""
end
end
end
claimSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
local Humanoid = claimSeat.Occupant
local Character = Humanoid.Parent
local player = game.Players:GetPlayerFromCharacter(Character)
if player then
if not ownerName and player:GetAttribute("IsOnBed") ~= true then -- check things
claimBed(player)
end
end
Humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
releaseBed(player)
end)
end)
15:29:33.177 Workspace.Beds.Bed1.Script:27: attempt to index nil with ‘Parent’ - Server - Script:27
it work with me tho, can u screenshot the explorer?
yup hold on my studio just crashed ill show you a screenshot with the output and explorer as soon as i get back on
for some reason it wont let me open your file it got blocked?
insert it to roblox studio not open it bc the file is rbxm
i did that but the file never opened after i put it into roblox.
yeah that is weird i really cant import from file can you show me the explorer and the properties in the bed?
why not send a link to the game for him and enable people take a copy of the place instead of sending a file of it