Hi guys, I’d like to know when to use returns when loading scripts
(2 Examples)
Hi guys, I’d like to know when to use returns when loading scripts
(2 Examples)
You could use the return keyword in loading scripts to terminate the rest of the execution of the particular thread, for example;
for _, v in AssetsFolder:GetChildren() do
if v:GetAttribute("Loaded") == true then
return
else
-- load the object
end
end
another example could be a module function to initialise data:
function module.LoadData(forWho: player)
if forWho:FindFirstChild("leaderstats") then
warn("Data already loaded for " .. forWho.Name .. ".")
return forWho:FindFirstChild("leaderstats")
else
createLeaderstats(forWho)
end
end
can you give me a second example please
You can use return to send values back to another thread, for example:
local function addNumbers(a, b)
return a + b
end
local result = addNumbers(5, 3)
print(result) -- Output will be 8
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.