Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i teleport a player to a seat?

Asked by 5 years ago

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?

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
5 years ago

Assuming you have the seats grouped or in a set folder, etc.You'd use :getchildren()

local seats = workspace.Seats:GetChildren() -- puts all seats in a table
local randomSeat = math.random(#seats)
-- randomSeat is a number, don't need a loop since you only need 1.

local selectedSeat = seats[randomSeat] -- this is your seat

-- Finally, set the player CFrame, assuming you have defined player

player.Character.HumanoidRootPart.CFrame = selectedSeat.CFrame

0
Thank you so mutch it worked! <3 But if sombody is sitting in 15 of the 16 seats. Will it teleport me to the last seat? Skydoeskey 108 — 5y
Ad

Answer this question