task.spawn() is used to run code in a separate thread, so that it can run at the same time as other things without yielding.
What you have there is just a weird way to run one function after the other. There is no new thread created, it’s just in sequence like everything else.
i really just want to be able to call functions in other functions regardless of placement
so i just create a empty function at the top of the script then actually set the function later so i can just call the function in another function w/o having to place the called function above it
What do you actually gain from creating a blank function then assigning it some code to run later? Why not just create the function and write the code for it at the same time
Looks like you’re trying to have functions accessible in code snippets above where they’re defined, but you’re also trying to avoid adding the function to the script’s environment/make the function global.
This seems like a code layout issue and could probably be fixed with some reformatting. But, if you really want to do it this way, you can just do this:
local func
local function a()
func()
end
func = function()
print("hi")
end
a() --> hi
If you want more safety, you can check to see if it’s been modified:
local function a()
if (type(func) == "function") then func() end
end
If you make a function or variable without the local keyword, you can access the contents anywhere in the script as long as the code has ran and assigned a value to it.
function a()
b()
print(hi)
end
hi = 5
function b()
end