wait(5) Start() function Start() print("This function has ran!") if game.Players.NumPlayers >= 2 then Yes() else No() end end function Yes() print("This function has ran!") wait(.1) end function No() print("This function has ran!") music = game.Workspace.HeartofCourage wait(1) music:stop() wait(5) music:play() music.Looped = true end
I have tried to fix it. This script is fricken' simple and it isn't working? Oh my god, imagine a complex script. Please tell me how I can fix this.
What it exactly says in the output window:
19:45:42.795 - Stack Begin 19:45:42.795 - Script 'Workspace.X', Line 2 19:45:42.796 - Stack End
Overpride, your calling a function that has not been defined yet, in this case I'm going to re-organize your script.
function Yes() print("This function has ran!") wait(.1) end function No() print("This function has ran!") music = game.Workspace.HeartofCourage wait(1) music:stop() wait(5) music:play() music.Looped = true end function Start() print("This function has ran!") if game.Players.NumPlayers >= 2 then Yes() else No() end end wait(5) Play()
You should define thing BEFORE you actually use them..
If the function is not defined before you call the function "Play()" , "Yes(), ","No()". Your going to get an error from the output saying that it is equal to nil.
Function definitions are actually local variable assignments.
The following two snippets are equivalent:
local a = function() ... end
function a() ... end
Looking at your code, then, we see:
-- Line 2, source of error: [Some use of Start] -- Line 4, definition of Start
Which is clearly a problem, because you are using something before it was ever defined (using its default value of nil
; specifically, calling its default value of nil
because this is a function call).
The call to Start()
has to occur after Start
and and functions that Start
references (Yes
and No
) have been defined, just like any code referencing variables has to be after the definition of those variables.