This code loops through the list of seats and teleports the players to a private server either a. after 20 seconds or b. when the four seats are occupied.
The second part detects when a player touches the “join group” part and checks if there are empty seats. If there are, it teleports the player into one.
The code is pretty simple imo but currently the player has no way to leave the seat without being immediately teleported back. My current plan is to add an gui button option to “Leave” that resets the character.
I think it all works but last time I thought that, I had a rather embarrassing experience during testing where matchmaking completely broke after 60+ people tried to join and teleport at once. I’m relatively inexperienced so I just want to make sure there isn’t any part that could potentially break if a user interacts with it wrong/at the wrong time.
-- defining variables. Fire is the model consisting of seats around a campfire
local fire = script.Parent.Parent
local seats = {fire.Seat1,fire.Seat2,fire.Seat3,fire.Seat4}
-- every second, change the timer sign and check if all the chairs are full
-- after 20, teleport either way
while true do
for i = 20,0,-1 do
wait(1)
script.Parent.Parent.Sign.SurfaceGui.Time.Text = i
local full = true
for i,v in pairs(seats) do
if not v.Occupant then
full = false
break
end
end
if full then
print("teleporting fire")
end
end
print("teleporting fire")
end
-- if a part is touched, try to find an empty seat and teleport the player to it
-- debounce of .1 seconds to minimize delay (is that too little?)
local debounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:WaitForChild("Humanoid") and not debounce then
debounce = true
for i,v in pairs(seats) do
if not v.Occupant then
v:Sit(hit.Parent.Humanoid)
break
end
end
wait(.1)
debounce = false
end
end)
rbxl:
CodeReview.rbxl (26.7 KB)