When using a while true statement with a return end statement, after the return end statement runs, the while true statement just stops working completely. Is it suppose to do that?
Example:
while true do
task.wait(1)
print("test 1")
local findItem = workspace:FindFirstChild("Spawn")
if findItem then
findItem:Destroy()
return
end
end
In theory it should print “test 1” every second and delete Spawn block. But I only see it print “test 1” once with the spawn block being destroyed. Might be bug or intentional I’m not very good at scripting.
If your code is in a function, then yes. This is because a function only expects one return value. (When you don’t return, you’re still returning nil (in other words, nothing) at the end of the function)
EDIT: The script itself is technically a “function”, it is a process too. ‘return’ will stop the code.