Is this possible?

Hey guys. I was wondering if it’s possible to get a variable without it being created earlier. Here’s what I mean.

local function AddApples(NumberOfApples: number)
    local Apples = NumberOfApples
end

AddApples(1)
print(Apples) -- nil because it didn't find "Apples", since it was created inside of a function.

Is it possible to get the “Apples” variable if it isn’t created earlier? Thanks to everyone that tries to help!

No because its out of scope but you can return it though

local function AddApples(NumberOfApples: number)
    local Apples = NumberOfApples
    return Apples
end

local Apples = AddApples(1)
print(Apples) -- This will print "1"
2 Likes

Alright thanks. I appreciate it. :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.