Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is the differerence between a local function and a normal function? [closed]

Asked by 7 years ago

What is the differerence between a local function and a normal function?

I have tried searching the web, saerching youtube, and searching the wiki, but I can't seem to find the difference.

What is the difference between these functions?:

When should I use the local function instead of the non-local function?

local function hey()
    --Code here
end

function hey()
    --Code here
end

Any help is greatly appreciated!

0
There really is no difference. It is the same as using local before a variable. If you use local, it can only be used in it's scope. Master_JJ 229 — 7y
0
Thanks guys iiParadoxLegacy 38 — 7y

Marked as Duplicate by User#5423 and BlueTaslem

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 7 years ago
Ad
Log in to vote
0
Answered by 7 years ago
Edited by M39a9am3R 7 years ago

A local function can only be used in that area of the script. The global function can be used everywhere. Similar to variables. Here is an example

function Random()
s = game
end

wait(5)

s.Workspace.Baseplate:Remove()
if Clicked then
Random()

--[[ I made up random stuff but this is merely an example. You would not be able to access those features if the variables and functions were global. Local usually stay in certain sections of the script. Again, I know this isn't how lua works with the whole end and stuff. Just giving an example.]]--

If you need me to explain more in depth, I will oblige