I wondered if a return that returns with nothing does anything
if not Player.Character:FindFirstChild("HumanoidRootPart") then
return
end
for example, what will the piece of code above do
I wondered if a return that returns with nothing does anything
if not Player.Character:FindFirstChild("HumanoidRootPart") then
return
end
for example, what will the piece of code above do
It will just stop whatever should run next.
local n = 5
if n == 5 then
return
end
print("This will not print.")
even outside of a function?----------------
Yes, everywhere in the script. When return is used inside a loop it will break it as well.
however the use of break when you want to break a loop is recommended
-- Example:
while true do
print("i no crash!")
break
end
It depends on the context too. When using return, it will stop the code after the loop in the current scope, while break won’t. For example:
while true do
break
end
print("This will print.")
while true do
return
end
print("This will not print.")
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.