Code crashes game

So my code keeps crashing my game
Help pls?

while true do
	task.wait()
	pcall(function()
		while true do
			print("Hello World!")
		end
	end)
end
1 Like

This probably crashes your game because there is no yield in it

1 Like
while true do
	task.wait()
	pcall(function()
		while true do
			print("Hello World!")
task.wait()
		end
	end)
end

its because theres no wait in the seconds loop

you are running a while true do within a while true do, causing it to print “hello world” excessively many times and increases every time the first while true do goes through.

Thank u it worked now!!! So happy

glad i could help. but why did you mark your own post as solution?

Because the thread has been solved.

ik but he marked his own post as solution. someone looking up “code crashes game” in a couple years is gonna see

It gives no info on how to solve it.

1 Like
while true do
	task.wait()
	pcall(function()
		while true do
			task.wait()
			print("Hello World!")
		end
	end)
end

You may want to correctly indent your code (not sure what IDE you’re using).

i typed it out inside the forum typer thing. all you did was copy and paste my code and pressed tab a few times.

No I just copied and pasted the code into an IDE which formats it correctly automatically (Roblox Studio).

Hello there. You should mark @luisgamercooI231fan 's comment as the solution if it worked, so that you can help others find it if they have a similar problem.

Marking your own comment as a solution may be confusing to newcomers. :slight_smile:

thats the same thing. Just without the tab part. You dont need to keep responding to me. Indentation doesn’t change how code works.

1 Like

Makes it more readable though, which should always be prioritised highly.

1 Like