Would while work when repeat task.wait() is inside

while table.find(loadedPlayers, tostring(player.UserId)) do
repeat task.wait() until player.Character:WaitForChild("HumanoidRootPart").CFrame == workspace.StationSpawns[stationName].CFrame
end

Lets say the Player is removed from the Table, will repeat task.wait() stop running when i use while?

1 Like

Can you describe exactly what your end goal is? Forget about the loop for a minute, just in general.

1 Like

Yeah, there’d definitely be better solutions then this

When the Player want to Spawn at a Part he is inserting into a Table and going to be teleportet to the Part, im waiting until the Player is teleportet to the Station because it can have a Delay.

But when the Player resets while its waiting until the Player is teleportet to the Part he will removed from the Table so the repeat task.wait() will run forever and when he wants to spawn again two functions are running then.

Do you know how to do it


It waits for the ‘thread’ inside the loop to finish before looping again. If your repeat loop stops yielding, then yes it will continue looping.

How could i stop repeat task.wait() until player.Character:WaitForChild("HumanoidRootPart").CFrame == workspace.StationSpawns[stationName].CFrame when player not found in Table

1 Like

I may be wrong, but I think you could check to see if the HumanoidRootPart has been found or not. If it hasn’t been found then use keyword Break to break the loop.

(for more info on breaking loops and just loops in general I suggest checking this out Loops)

Replace the WaitForChild to FindFirstChild so that it would check if the humanoid root part is nil then add if not player then break end before the repeat loop.

Yeah that’s what I was thinking

(too)

do this just to be sure:

while table.find(loadedPlayers, tostring(player.UserId)) do
   if player then if player.Character then
      repeat if not player then return end task.wait() until player.Character:FindFirstChild("HumanoidRootPart")
      repeat if not player then return end task.wait() until player.Character:FindFirstChild("HumanoidRootPart").CFrame == workspace.StationSpawns[stationName].CFrame 
   end end
end

because it would cause an error if it its in the repeat loop then the player went nil

while table.find(loadedPlayers, tostring(player.UserId)) do
	repeat task.wait() until player.Character:WaitForChild("HumanoidRootPart").CFrame == workspace.StationSpawns[stationName].CFrame or not table.find(loadedPlayers, tostring(player.UserId))
end
1 Like

Okay i try that and i have a question

if not table.find(Passengers, tostring(player.UserId)) and not table.find(Drivers, tostring(player.UserId)) and table.find(loadedPlayers, tostring(player.UserId)) then -- *
			
if workspace.StationSpawns:FindFirstChild(stationName) then
				
table.insert(Passengers, tostring(player.UserId))
				
player.Character:WaitForChild("HumanoidRootPart").CFrame = workspace.StationSpawns[stationName].CFrame

repeat task.wait() until player.Character:WaitForChild("HumanoidRootPart").CFrame == workspace.StationSpawns[stationName].CFrame or not table.find(Passengers, tostring(player.UserId)) -- **

end

Lets say somebody using a Cheat Tool and with the Cheat Tool somoene can click 1000 Times per second (example) Could i remove me from table and insert me again in table fast before task.wait() ends so that the * Function would run again and ** would fire then, so the Function would run in the moment 2 Times? Would this be possible or not because somoene said task.wait() is 0.1 seconds long