Well this code snippet will error, because value isn’t defined anywhere.
Is this what you mean?
local test = true
local function testFunction(value)
print(tostring(value))
end
if test == true then
testFunction(10) -- Change 10 to any number, and the function will print it!
wait(1)
testFunction(20) -- One second after 10 was printed, it will print 20!
end
The code snippet does not error. the value that you are passing into testFunction becomes a variable that your function can access. Also, when printing numbers with print you do not need to use tostring
OP’s question has to do with variable scope. That is where variables are able to be accessed. the simplest way to do this is to define it before as @Chromatype has shown. There is another way that you can do this though. You can do as @TheShowCaseMaker has done and create a global variable which is just a variable that does not have a local before it. This variable is able to be accessed anywhere. the local keyword before a variable makes the variable only be able to be accessed from its scope. You can read more about variable scope here: Scope | Roblox Creator Documentation