"Wait until" code stops entire script

how come this code doesn’t work? when the game script gets to this point the output says stack end instead of continuing the script.

repeat wait() until game.StarterPlayer.StarterCharacterScripts.CheckIfPlayerIsInArea2.Value == true

Can you send the full error/what the output says. Take a screenshot of it.

Here, perhaps try a few alternatives.

  1. Adding a wait() period; sometimes using wait() without a value can be faulty.
repeat wait(0.05) until game.StarterPlayer.StarterCharacterScripts.CheckIfPlayerIsInArea2.Value == true
  1. Using a while loop instead of repeat.
while (game.StarterPlayer.StarterCharacterScripts.CheckIfPlayerIsInArea2.Value == false) do end

Or, with a wait() period,

while (game.StarterPlayer.StarterCharacterScripts.CheckIfPlayerIsInArea2.Value == false) do wait(0.05) end
  1. There are better ways to go about this than stalling a script with a loop. You could try using a .Changed() event, which I personally have used quite a bit. (API Reference: BoolValue | Roblox Creator Documentation)
    if newValue == true then
        -- Do whatever you wanted to, that was below the loop in your example

I tried all of those and they didn’t work, although if I put it in a different code it works. Can it only be at the start of the code?
code that doesn’t work:

	CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"Let's split up to cover more ground.")
	repeat wait() until game.StarterPlayer.StarterCharacterScripts.CheckIfPlayerIsInArea2.Value == true
	CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"it worked")

code that does work:

repeat wait() until game.StarterPlayer.StarterCharacterScripts.Area2.Value == true

	if e.Name == "Head" and e.Parent.CheckIfPlayerIsInArea2.Value == false then
		e.Parent.CheckIfPlayerIsInArea2.Value = true

You can use the built-in function named “spawn” to create a new thread outside of the main thread.


This way your entire script will not yield.

1 Like

I’m assuming this checks if their in the designated area, I want to recommend checking out this useful module.

You can call a Instance | Roblox Creator Documentation event instead of repeating it. This is faster AND more reliable. It also won’t lag the game. :slight_smile:

You posted this same question in another thread where you got tons of answers. Why haven’t you gone back and tried those instead of creating an entirely new thread about the same issue? You’re just gonna get the same answers.

  1. You shouldn’t reference StarterCharacterScripts because everything in there is replicated to the character, so reference the character.
  2. Instead of using repeat wait() until, use the Value.Changed event or Instance:GetPropertyChangedSignal(“Value”).

Both of these things were already reiterated in your previous post about the exact same problem. If those solutions didn’t work, you should’ve replied to those people saying they didn’t work for you.