Oh you must’ve not read it. On my earlier post (before I accidently edited it), I said to reference the seats instead of the chairs themselves.
If inside of “Chair1”, “Chair2”, etc is “Seat” in each of them, then use this code:
-- Services
local Players = game:GetService("Players")
-- Variables
local chairFolder = game.Workspace.ChairFolder
-- Table to hold the chair variables, and if they're taken or not
local seatStatus = {
{chair = chairFolder.Chair1.Seat, taken = false},
{chair = chairFolder.Chair2.Seat, taken = false},
{chair = chairFolder.Chair3.Seat, taken = false},
{chair = chairFolder.Chair4.Seat, taken = false}
}
function seatPlayers(player)
local character = player.Character or player.CharacterAdded:Wait()
local hum = character.Humanoid
hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) -- To make the player unable to jump
if hum then
-- Looks through all seats in table and checks if they're taken
for i, v in pairs(seatStatus) do
if v.taken == false then -- If it's not taken, it will sit player in it, and stop looping through the table
v.chair:Sit(hum)
v.taken = true
break
else -- If it is taken, it will continue until the end of the table, or until it finds a chair not taken
end
end
end
end
Players.PlayerAdded:Connect(seatPlayers) -- Fires the seatPlayers function when a player joins the game
Added a short wait to see if it helps, and changed “character.Humanoid” to “character:FindFirstChildOfClass(“Humanoid”)” in order to make sure it finds the humanoid, no matter what it’s called.
-- Variables
local chairFolder = game.Workspace.ChairFolder
-- Table to hold the chair variables, and if they're taken or not
local seatStatus = {
{chair = chairFolder.Chair1.Seat, taken = false},
{chair = chairFolder.Chair2.Seat, taken = false},
{chair = chairFolder.Chair3.Seat, taken = false},
{chair = chairFolder.Chair4.Seat, taken = false}
}
function seatPlayers(player)
local character = player.Character or player.CharacterAdded:Wait()
local hum = character:FindFirstChildOfClass("Humanoid")
hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) -- To make the player unable to jump
if hum then
-- Looks through all seats in table and checks if they're taken
for i, v in pairs(seatStatus) do
if v.taken == false then -- If it's not taken, it will sit player in it, and stop looping through the table
wait(0.5)
v.chair:Sit(hum)
v.taken = true
break
else -- If it is taken, it will continue until the end of the table, or until it finds a chair not taken
end
end
end
end
Players.PlayerAdded:Connect(seatPlayers) -- Fires the seatPlayers function when a player joins the game
I’m aware this post is 3+ years old at this point and hasn’t been active in forever but did anyone ever figure this out?
This could be useful information to many new developers and would be an awesome post into the community resources tab.
local Seats = workspace.Seats -- a folder in workspace containing all the seats.
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
for _, v in pairs(Seats:GetChildren()) do
if v:IsA("Seat") or v:IsA("VehicleSeat") then
if v.Occupant == nil then
task.wait()
v:Sit(hum)
end
end
end
end)