roblox local and global variables
-- A LOCAL variable is accessible only in the block where it’s declared.
-- Local variables are declared using the local statement:
if true then
local myNumber = 50
myNumber = myNumber + 10 -- This will work because is Inside the code Block
end
myNumber = myNumber + 10 -- This wont work because we cannot access it
print(myNumber) -- This wont work also because your code got broken from before
-- A GLOBAL variable looks like this
-- You just take the local part away
if true then
myNumber2 = 50
myNumber2 = myNumber2 + 10 -- This will work because is Inside the code Block
end
myNumber2 = myNumber2 + 10 -- This WORKS because it was declared globally
print(myNumber2)