Lock player to seat

My problem: How do I lock a seat so that NO other player can sit except the original player who sat down first.

My code so far:

I’ve tried to make a check with the A1_a1, but ofc, when a new player sits down that player becomes A1_a1. I’ve tried using Developer Wikia, but haven’t found anything to help me. I’m really stuck, and anything would be helpful, thanks.

4 Likes

You can actually disable the seat with a simple script

local seat = script.Parent
seat.Disabled = true
1 Like

Easiest way possible is to check who sat down in the seat and if they are not the original occupant, make them jump.

You can access the seated humanoid using Seat.Occupant as well.

1 Like

Yea Usering but he wants to Disable,not check if its occupied

1 Like

Best thing to do is to find the person who touched first,basically find the hit.Parent and make it only seatable to the Parent

Just activate the seat if the corresponding player touches it.

the seat can hold an int value with the UserId of first player

well you can count how many times it was touched and fidn the player who added the first 1 to the variable,like so

local Player = game.Players.LocalPlayer
local Players = game.Players
local touched = 0

script.Parent.Touched:Connect(function(hit)
touched.Value = touched.Value +1
if hit.Parent == Players then
-- whatever down here
end)

as this might not be right this is just a prime example

1 Like

I got a bit confused over the title and what you are actually asking.

You might want to rename it to something like “Lock seat to other players” or something.

Either way, you can do it:

  1. Saving which player sat first, and make anyone jump if they’re not the original player (like Usering said)

  2. You could disable the seat for the server(server script), which will replicate to every client. After so, enable it back for the client using a localscript

  3. Or like someone also said, enable/disable it according to who touched the seat.

2 Likes

Yea i totally got confused,your title should be named “How to Disable a seat”
@johanjv mark one of our replies as a Solution(mines pls im lonely)

1 Like

Should accept the one that actually helped and not the one that a player asked to be.

1 Like

Well its more than disabling, title should be “Player owned seat” or “Claimable seats”

1 Like

Add a changed event to the seat and if someone sits in it you make them the owner, if another person sits on it and isn’t you force them to get back up.

(This script isn’t going to work if you paste it into the seat, it’s just an example of what you would do)

local owner = nil
seat.Changed:Connect(function()
if seatOwner then
newHumanoid.Sit = false
elseif owner == nil then
owner = humanoid
end
end)

I wrote this up real quick given how OP wanted the system to work. Wasn’t able to test, but this should work in theory

local seat = workspace.Seat
local originalOccupant

local lastTouch = 0

seat.Touched:connect(function(hit)
	if tick() - lastTouch > 2 then
		lastTouch = tick()
		local hum = hit.Parent and hit.Parent:FindFirstChild("Humanoid")
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player and hum then
			if not originalOccupant then
				originalOccupant = player
			elseif originalOccupant ~= player then
				return
			end

			seat:Sit(hum)
		end
	end
end)
1 Like