"Repeat wait() until" does not work

no, i think it might be more than the one line thats causing it to stop


to fix this what do I add to this code? before the “if and” do I put another “if” asking if it is not the monster?

would this work (head monster as in the monster’s head):

if e.name ~= "HeadMonster" then

The error is from TutorialMonster not having a child called “CheckIfPlayerIsInArea” when a . operator is used (ex: instance.name). You’d either need to check if it exists or wait for it to exist. If it never exists, then you’re problem is from much more than the code you shared.

I’d need more info to debug your problem.

can I instead just copy CheckIfPlayerIsInArea to the tutorialMonster

Why doesn’t you tutorial monster just already have that BoolValue inside of it?

I’m adding my own scripts on top of what the tutorial teaches

I added the bool to the tutorial monster and it fixes the red error but this orange one still remains:

Infinite yield possible on 'Workspace.tutorialMonster:WaitForChild("Humanoid")'

Someone said this is 'cause the humanoid is called Zombie but if I change it to Humanoid it says

Zombie is not a valid member of Model "Workspace.tutorialMonster"

Replace :WaitForChild("Humanoid") with :WaitForChild("Zombie")

The first error means that that line of code, :WaitForChild("Humanoid") might wait forever for a child named “Humanoid”. Your Humanoid is named “Zombie” so you’ll need to use :WaitForChild("Zombie") to get it.

the thing is the script is actually trying to check for a player inside the area but it also detects the monster as a player so if I change humanoid to zombie it won’t work either

also, the error occurs when the monster leaves the area

Is it working properly without the repeat until?

Yes it is working without the repeat until

UPDATE: It seems to work before I get this error:

Infinite yield possible on 'Workspace.tutorialMonster:WaitForChild("Humanoid")'  -  Studio

Anyone know how to fix this? My guess is that it’s trying to damage it’s own Humanoid which is called Zombie

--Responsible for regening a player's humanoid's health

-- declarations
local Figure = script.Parent
local Head = Figure:WaitForChild("Head")
local Humanoid = Figure:WaitForChild("Humanoid")
local regening = false

-- regeneration
function regenHealth()
	if regening then return end
	regening = true
	
	while Humanoid.Health < Humanoid.MaxHealth do
		local s = wait(1)
		local health = Humanoid.Health
		if health > .1 and health < Humanoid.MaxHealth then
			local newHealthDelta = 0.01 * s * Humanoid.MaxHealth
			health = health + newHealthDelta
			Humanoid.Health = math.min(health,Humanoid.MaxHealth)
		else
			game.StarterPlayer.StarterCharacterScripts.Jumpscare.Value = true
		end
	end
	
	if Humanoid.Health > Humanoid.MaxHealth then
		Humanoid.Health = Humanoid.MaxHealth
	end
	
	regening = false
end

Humanoid.HealthChanged:connect(regenHealth)
2 Likes

If its own humanoid is named “Zombie”, then you need to change the name of the Humanoid to “Zombie”