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:
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)