✓ Accepted answer
It is like any other programming language. It is like someone asking you what "print('Hello world!')" means and expecting you to know what it is, and afterwards telling you what that means. It is like asking why the following does not print 6.
local var = 3
print(var)
local var = 6
Code runs from up to down, not just picking a random line and running it.
So, once it realises what playMusic() means it is too late, as the script already gave an error about how playMusic() is not defined.
This is why some people like defining variables and functions at the beginning at the script
local something = 'a'
function nothing()
return
end
print(something, nothing())
but if you don't, until you realise you are using something a lot and want a variable for it. You already have working code, but if you had a variable, it would save some time.
Hope this helps!
4 comments
After reading your answer, I assume that Roblox Lua does not support the use of forward declaration of a function like in C, where you can access the function from anywhere?
I'm pretty sure it is in all programming languages.
not all programming Languages do this - hiimgoodpack - for example, Java in some parts of its functionality is greatly object oriented and as such does not require u to pre-define functions like python does
I said "I'm pretty sure", not "I'm sure".