Only 3 players are sitting and one is at spawn
You are checking and then waiting and then finally seating.
Itâs like being told youâre first in queue and when you show up, 3 others also were told that.
So youâd have to task.wait(5) or task.wait(10) before running the whole script once the player joins. (Or just before it checks and sits)
EDIT: Also remove the task.wait() line before it seats them or else the same thing will happen.
I removed the task.wait and it flung the characters
Can I see the updated code (Just the chunk with PlayerAdded event)
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
task.wait(5)
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
end)
What is the point of that second loop?
I JUST UPDATED A SECOND AGO BECAUSE OF A TYPO, TRY BELOW CODE AGAIN-
Try 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
task.wait(10)
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
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
seat:Sit(character.Humanoid)
break
end
end
end)
end
end
end)
âYOOO, that might actually work,â -swedesask 5 seconds ago
It still kicks one of the players up
Did you try the new code or the one I accidentally sent lol.
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
task.wait(10)
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
seat:Sit(character.Humanoid)
break
end
end
end)
Try this one without that second loop reseating everyone. Iâm not sure if thatâs why the characterâs jumping out, but thatâs weirdâŚ
Pog
Try a few more times to verify it actually works with good success rate.
I did not expect this to be such a lengthy fix.
It was all because of that second loop, also the task.wait at the start of the function is also helpful but cant put 2 solutions
I suggested deleting it ~10 posts ago
Oh well, the problemâs resolved at least and I can finally enjoy these 4 hours of sleep.
Have a good day/night!!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.