Simple Script is Erroring

Script:

print(player.Name .. " asked " ..  script.Parent.Name .. " to " .. NearestNPC.Name)
TellJoke(player, script.Parent, NearestNPC)

Output:
image

Why would this be erroring as all three paramaters exist?
image
The function is just this, super simple.

Any help, helps! Cheers - lux

Where is the TellJoke function defined?
The function itself is likely the nil value the error is referring to.

Underneat the script, is this a issue? Would I need to place it above where the script is located?

image

It’s generally good practice to define all your global variables and functions at the top of the script.

Another possible issue may be that if that while loop never terminates, the code below it would never be reached. Which is another reason to handle declarations at the beginning of the script.

1 Like

When you call the function, it hasn’t been defined yet, hence the error. Define functions before you use them. Also please try to use local declarations for functions.

1 Like

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