I am working on a racing script that will teleport you to the cars during the start and then back into the lobby after the race finishes, but I only want players that are in the racing lobby to teleport.
Here is my current teleport players code:
function teleportPlayers(target)
for _, player in pairs(game.Players:GetChildren()) do
while player.Character == nil do
wait()
end
local character = player.Character
local torso = character:WaitForChild("Torso")
torso.CFrame = target.CFrame
end
end
I also have this variable already set
local racingZone = game.Workspace.RacingZone.RacingZoneDetector
It is connected to the startup script that runs the race, so that when a player enters the RacingZoneDetector, the script starts. I only want the players that are inside of the RacingZoneDetector to teleport to and from the racetrack, though.
Here is the code I used to check the RacingZoneDetector:
function raceZoneCheck(otherPart2)
print("RaceZoneHit")
print(otherPart2.Name)
if otherPart2 ~= nil and otherPart2.Parent ~= nil and otherPart2.Parent:FindFirstChild("Humanoid") then
if not racingZone:FindFirstChild("Activated") then
print("Activated by Player")
local enterTag = Instance.new("StringValue")
enterTag.Parent = racingZone
enterTag.Name = "Activated"
raceTrackEntered()
end
end
end
racingZone.Touched:connect(raceZoneCheck)
here is the raceZoneCheck function that it is connected to
function raceTrackEntered()
print("Racing Zone Entered")
if racingZone:FindFirstChild("Activated") then
while true do
after the while true do, it runs all of the functions that run the race, like checkpoints and create cars.
If you can help me, that would be great. I am just a beginner and I have been working on this code for a week, and I could not figure it out. Thank you!

2 comments
Could you clarify what RacingZoneDetector is? Is it a part? How large is it?
Sorry! Yes, RacingZoneDetector is an invisible part that covers the entire racetrack, and it monitors when people enter and exit.