Problem with a function

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to find the bug and solve it.
  2. What is the issue? Include screenshots / videos if possible!
local index = gP("tusart")

function gP(t)
	for index,player in pairs(PlayersTable) do
		print(tostring(player) == t, tostring(player),t)
		if tostring(player) == t then
			return index;

Whenever I call the function, this error appears:

And no, nothing prints.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes, nobody has helped me so far.

Sorry if this is some kind of easy fix, I can not find for an hour.

From the looks of your code, you’re calling the function before you create it, try moving the local index = gP("tusart") below the function?

Thank you. I changed function to local function and added it above the variable. Changing the position of the function is better in this situation, thank you!

1 Like