Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

3 comments

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.

0

Thanks guys

2 answers

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

This discussion is preserved as it was. New answers, comments, and votes are closed.