Assign Seat To Players

Hi Everyone, I want to make a system, there are three seats, and when a player touches a part, it will get spawned onto the seat, then another player will touch a part but it will spawn in the remaining two instead and so on, How can i avhieve this?

You could use dictionaries to achieve your seat assignment idea. Here’s an example.

-- If the value is not false, it is occupied.
local AssignSeatPart = -- A part
local SeatAssignment = {[1] = false, [2] = false, [3] = false}

AssignSeatPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        for i, v in pairs(SeatAssignment) do
            if not v then
                SeatAssignment[i] = hit.Parent
                break
            end
        end
    end
end)
1 Like

This should work.

local part = script.Parent

local seats = workspace.Seats --add your directory

part.Touched:Connect(function(hit)
  if game.Players:GetCharacterFromPlayer(hit.Parent) then
    local found = false
    local humanoid = hit.Parent.Humanoid
    for i, v in pairs(seats:GetChildren()) do
     if not seat.Occupant and found == false and not humanoid.Sit then
       found = true
       v:Seat(humanoid)
     end
    end
  end
end)

Please mark this as Solution if this answered your question.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.