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

What is the purpose of a local function?

1 answer

There's not much of a difference. All the local statement does is declare a local variable. local variables do not carry between functions, for statements and if statements.

If i were to run this code it would print false since the if statement it changes c locally.

local c = false
if true then
local c = true
end
print(c)

The same thing with functions if i ran this code it would output hi.

local c = function()
	print("hi")
end

if true then
	local c = function()
		print("bye")
	end
end
c()

If i were to run this code it would output bye since the if statement doesn't declare it locally.

oof = function()
	print("hi")
end

if true then
	oof = function()
		print("bye")
	end
end

oof()

-ThisIsAnAccount255

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