Unreachable code

Hello!

I have a function inside of my script and some part of a function is unreachable. I don’t know why and I don’t get any warnings or errors.

The code:

local start = coroutine.wrap(function()
	while active == true do
		for index, Object in pairs (workspace:GetDescendants()) do
			if Object.Name == 'Humanoid' then
				local mag = (script.Parent.TouchBrick.Position-Object.Parent.HumanoidRootPart.Position).magnitude
				print(mag, script.Parent:GetFullName()) -- Unreachable
				if mag <= script.Parent.Range.Value then
					Object:TakeDamage(20)
				end						
			end
		end
		wait()
	end	
end)

This is supposed to kill anyone close to the script’s parent. I added a print statement to get what was wrong, and it’s just printing nothing. What’s wrong?

You forgot to call the function.
Last line:

end)()

The function is being called in another part of the code that I don’t want to expose. I tested and the function is indeed running and being called. Objects are going into the if Object.Name == 'Humanoid' then statement, but the print function and the code under it is unreachable.

Nevermind, managed to fix it. The problem was in another module in my game.

1 Like