Putting players into seats when joined not working

Screenshot 2025-02-20 014557
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

:skull:

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?

1 Like

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

1 Like

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…

1 Like

Guys i think it works:

1 Like

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.

1 Like

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

2 Likes

I suggested deleting it ~10 posts ago :pensive:
Oh well, the problem’s resolved at least and I can finally enjoy these 4 hours of sleep.

Have a good day/night!!

1 Like

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