You know how a function like placeholder_part:IsA("Part")
will return true if the instance is a part, and false if not?
return
works by giving out a result when a function is called:
local function Chat(part,message)
--This example is just a shortened version of using game.Chat:Chat()
local chat = game:GetService("Chat")
return chat:Chat(part,message)
end
Chat(workspace.Part,"hello") --Part will say "hello" with bubble chat
It’s also commonly used to stop a function from further executing, for example, if a conditional is not met.
local cooldown = false
...
if cooldown then
return --Stops the function from going further
else
... --Code, if the conditional (cooldown in this case) is met
end