Auto sit on join not working correctly

Hello all,

I have been trying to create a script that auto sits the player when joining the experience. But things aren’t quite working out properly, the code seems fine but some players aren’t getting seated.

Here is the script:

local Players = game:GetService("Players")
local seats = game.Workspace.Chair:GetChildren()

function sitPlayers(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local hum = character:FindFirstChild("Humanoid")

	if hum then

		for i, v in pairs(seats) do
			if not v.Occupant then
				task.wait(1)
				v:Sit(hum)
				print(character.Name.." has sat in chair "..v.Name)
				break
			end
		end
	end
end

Players.PlayerAdded:Connect(sitPlayers)

Here is a picture of the output and the game showing the players not being seated:

I also noticed how different players tried to get seated into the same chair, not sure if this could be the issue?

Any help will be much appreciated, thank you!

do that with CharacterAdded event instead, should fix the problem
OR
change character:FindFirstChild("Humanoid") to character:WaitForChild("Humanoid")

1 Like

Still not working unfortunately, it seems to not be seating 3 players no matter what.

Here’s the updated script:

local Players = game:GetService("Players")
local seats = game.Workspace.Chair:GetChildren()

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		
		local hum = char:WaitForChild("Humanoid")
		
		if hum then
			
			for i,v in pairs(seats) do
				if not v.Occupant then
					task.wait(0.5)
					v:Sit(hum)
					print(char.Name.." has sat in chair "..v.Name)
					break
				end
			end
		end
	end)
end)

Here’s the output:

remove the task.wait() there is no need to put it there, since using CharacterAdded solves the problem with timings

1 Like

Life saver, thank you so much!

It’s always the simple things :man_facepalming:

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