I am making a script where when the players join into the match/game, it puts them into individual seats. There are 18 seats and if 18 players are in the match, the chairs must be full. My script has an error that is like this:
local Players = game:GetService("Players")
local chair = script.Parent
local seats = {}
for _, child in chair:GetChildren() do
if child:IsA("Seat") then
table.insert(seats, child)
end
end
local playerSeatMap = {}
local seatsAssigned = false
Players.PlayerAdded:Connect(function(player)
if seatsAssigned then return end
local character = player.Character or player.CharacterAdded:Wait()
for _, seat in seats do
if not seat.Occupant then
playerSeatMap[player] = seat
seat.Occupant = character:WaitForChild("Humanoid")
break
end
end
for _, existingPlayer in Players:GetPlayers() do
if existingPlayer ~= player then
task.spawn(function()
for _, seat in seats do
if not seat.Occupant then
playerSeatMap[existingPlayer] = seat
seat.Occupant = existingPlayer.Character:WaitForChild("Humanoid")
break
end
end
end)
end
end
seatsAssigned = true
end)
Players.PlayerRemoving:Connect(function(player)
local seat = playerSeatMap[player]
if seat then
seat.Occupant = nil
playerSeatMap[player] = nil
end
end)
local Players = game:GetService("Players")
local chair = script.Parent
local seats = {}
for _, child in chair:GetChildren() do
if child:IsA("Seat") then
table.insert(seats, child)
end
end
local playerSeatMap = {}
local seatsAssigned = false
Players.PlayerAdded:Connect(function(player)
if seatsAssigned then return end
local character = player.Character or player.CharacterAdded:Wait()
for _, seat in seats do
if not seat.Occupant then
playerSeatMap[player] = seat
character:WaitForChild("Humanoid")
task.wait(0.01)
seat:Sit(character.Humanoid)
break
end
end
for _, existingPlayer in Players:GetPlayers() do
if existingPlayer ~= player then
task.spawn(function()
for _, seat in seats do
if not seat.Occupant then
playerSeatMap[existingPlayer] = seat
task.wait(5)
seat:Sit(character.Humanoid)
break
end
end
end)
end
end
seatsAssigned = true
end)
Players.PlayerRemoving:Connect(function(player)
local seat = playerSeatMap[player]
if seat then
seat.Occupant = nil
playerSeatMap[player] = nil
end
end)
I removed task.wait and it just teleported a single player to the seats.
The game called “Sacrificer”. The game is about surviving a bunch of games without dying. Once they join, they queue up and get teleported to the match. Then they get into a bunch of CHAIRS waiting for the others. And then explains how to play from the narrator.
local Players = game:GetService("Players")
local chair = script.Parent
local seats = {}
for _, child in chair:GetChildren() do
if child:IsA("Seat") then
table.insert(seats, child)
end
end
local playerSeatMap = {}
local seatsAssigned = false
Players.PlayerAdded:Connect(function(player)
if seatsAssigned then return end
local character = player.Character or player.CharacterAdded:Wait()
character:WaitForChild("Humanoid").JumpHeight = 0
for _, seat in seats do
if not seat.Occupant then
playerSeatMap[player] = seat
character:WaitForChild("Humanoid")
task.wait(0.05)
seat:Sit(character.Humanoid)
break
end
end
for _, existingPlayer in Players:GetPlayers() do
if existingPlayer ~= player then
task.spawn(function()
for _, seat in seats do
if not seat.Occupant then
playerSeatMap[existingPlayer] = seat
task.wait(0.05)
seat:Sit(character.Humanoid)
break
end
end
end)
end
end
end)
Players.PlayerRemoving:Connect(function(player)
local seat = playerSeatMap[player]
if seat then
playerSeatMap[player] = nil
end
end)
for _, existingPlayer in Players:GetPlayers() do
print("a")
if existingPlayer ~= player then
print("b")
task.spawn(function()
for _, seat in seats do
print("c")
if not seat.Occupant then
print("d")
playerSeatMap[existingPlayer] = seat
task.wait(0.05)
seat:Sit(character.Humanoid)
break
end
end
end)
end
end