Here is a example script. I will call it script one.
local UserInputService = game:GetService("UserInputService") local Key = 'Q' UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode[Key] and Debounce and Char then Debounce = false local LoadAnimation = Char.Humanoid:LoadAnimation(Animation) LoadAnimation:Play()
And this is another example. Script two.
game.Workspace.Player.Humanoid.Running:Connect(function(speed) if speed > 0 then print("Player is running") else print("Player has stopped") end end)
Why did the scripter not use "return end" on script two? They just used end right after print.
here is a piece of confusion in this question.
You ask what the difference is between return end
and end
. However, this alone isn't really a meaningful question.
end
is a keyword used to signify the end of an if
, while
, for
, and function
scope.
If you do not understand how the return
keyword works, I will explain. If you do already, you can skip this.
What it does is either return a value from a function, prematurely end a function, or both.
local function getSum(x, y) return x + y -- returns the sum of x + y end local sum = getSum(8, 25)
The sum
variable holds the "result" of the function. In this case the result is 33, because the function returns the sum
of two numbers. Not all functions have return values. Another example of a function that has a return value is wait
. Now this function has two return values; the delta time (time waited) and the time since the program started.
local dt, timeSinceProgramStarted = wait(3) print(dt, timeSinceProgramStarted) --> 3.00038384925, 3838.9 (just an example, you will get different numbers)
You can prematurely end a function, if, for example, a condition is NOT met.
local pizzaPrice = 15 local function orderPizza(customer) if customer.Money.Value < pizzaPrice then return -- return out of the function if they do not have enough money end -- Function won't even reach here if the condition above was met. customer.Money.Value = customer.Money.Value - pizzaPrice -- give them their pizza end
If a function reaches a return, the entire function stops. The developer probably didn't want the entire function to stop.
for example, u can do
if thing ~= nil then print("thing is nil") end
instead of
if thing ~= nil then print("thing is nil") end
then return end should be fashioned similarly:
if thing ~= nil then return end
instead of
if thing ~= nil then return end
im sorry if i got ur question wrong im also not rly sure what im doing; but i believe return end is just something ppl like to do; like
local function thing() end
instead of
function thing() end
although they are pretty much the same
Locked by User#24403, DinozCreates, and Amiaa16
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?