So I want to write a script that makes a player teleport to a seat. I have 16 seats and I want to make it so you get teleported randomly to one of them. But I want it not to teleport to a seat that is occupied How do I do this?
Assuming you have the seats grouped or in a set folder, etc.You'd use :getchildren()
1 | local seats = workspace.Seats:GetChildren() -- puts all seats in a table |
2 | local randomSeat = math.random(#seats) |
3 | -- randomSeat is a number, don't need a loop since you only need 1. |
4 |
5 | local selectedSeat = seats [ randomSeat ] -- this is your seat |
6 |
7 | -- Finally, set the player CFrame, assuming you have defined player |
8 |
9 | player.Character.HumanoidRootPart.CFrame = selectedSeat.CFrame |