Hey peeps I’m no genius scripter so bear with me, I’m trying to use a force sit script to make people sit on a couch as apart of the games loading screen, and to make it so when a seat is taken say seat1, the next player to join is put into seat2.
I feel like my code should work in theory but I haven’t been able to produce it.
local Players = game:GetService("Players")
local num = 1
local Chair = workspace.SpawnBox.Couch:FindFirstChild("Seat") or workspace.SpawnBox.Couch:WaitForChild("Seat")
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
repeat
task.wait(1)
until char:FindFirstChild("Humanoid")
task.wait()
if Chair.Occupant == nil then
Chair:Sit(char:WaitForChild("Humanoid"))
else
num = num +1
Chair = workspace.SpawnBox.Couch:FindFirstChild("Seat"+num) or workspace.SpawnBox.Couch:WaitForChild("Seat"+num)
task.wait()
Chair:Sit(char:WaitForChild("Humanoid"))
end
end)
end)
I’ve been pretty stumped on this for a couple days now, the code doesn’t give me any syntax errors cause it all should be correct and the script works when one player joins but not two.
Does nothing happen when the second player joins? I can see a few potential falls but these are merely speculation.
To shorten the code try using char:WaitForChild("Humanoid') initially instead of the loop
Are the seats numbered correctly? Like its Seat1 then Seat2 or is it Seat then Seat1? Cause it doesn’t ever look for Seat1 which I think might be the issue
important: I am assuming that the seats are named in this format: seat → seat1 → seat2
Using these points try giving the following block a try and lmk if it works or provides some hints to the specific breakdown:
local Players = game:GetService("Players")
local num = 0
local Chair = workspace.SpawnBox.Couch:WaitForChild("Seat")
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
if not Chair.Occupant then
Chair:Sit(humanoid)
print("Sat down: " .. plr)
else
num += 1
print("Unable to find a seat. Trying to seat on seat" .. num)
Chair = workspace.SpawnBox.Couch:WaitForChild("Seat" .. num)
-- Check if we were able to find the new chair
if not Chair then warn("Unable to find the chair in the SpawnBox") return end
-- Chair was found now sit the player
Chair:Sit(char:WaitForChild("Humanoid"))
end
end)
end)
Lmk if you run into any trouble or what the output is if it still isn’t working or if it errors
Yup this fixed it, appreciated! It did break another script that controls player transparency since I was using one spawn room for every player, but I’ll just use the simple solution of making more spawn boxes since the games servers will only allow around 20 players