file.Exists problem (Newbie developer :/)

Hi people! This is my first post on facepunch. I decided to make an account and make a post about my problem.
I’m recently started making gmod addons (simple and test ones).
Today I’m making the most complicated and complexed addon I ever made :confused:
But I have found a problem that i cant solve.


[ERROR] addons/rpcharacter/lua/rpcharacter/server/sv_functions.lua:7: bad key to string index (number expected, got string)
  1. error - [C]:-1
   2. __index - lua/includes/extensions/string.lua:310
    3. hasCharacter - addons/rpcharacter/lua/rpcharacter/server/sv_functions.lua:7
     4. unknown - addons/rpcharacter/lua/rpcharacter/server/sv_commands.lua:2
      5. unknown - lua/includes/modules/concommand.lua:54


local meta = FindMetaTable( "Player" )

function meta:getCharacterFile() return "rpcharacter/characters/" .. self:UniqueID() .. ".txt" end

function meta:hasCharacter()
	local file = self:getCharacterFile()
	return file.Exists( "data", "GAME" ) -- Line 7. ERROR IS HERE


concommand.Add("chdebug", function(ply)

Also i tried to google it but I found nothing that could fix it.
May someone help me and explain why this is not working?

EDIT: added error line

Line 7 is trying to index the string you set on line 6 rather than the file library. Change your file variable’s name.

The rest of the code is wrong too.

function meta:hasCharacter()
	return file.Exists( self:getCharacterFile(), "DATA" ) -- Line 7. ERROR IS HERE

Thanks that worked!
I changed the function to:

function meta:hasCharacter()
	local path = self:getCharacterFile()
	return file.Exists( path, "DATA" )

and it worked :wink:
I think it’s better i do the variable like I do in expression2 of wiremod first letter in upper case

Wow you answered too quickly, it’s hard to write using iPad keyboard…

[editline]9th May 2015[/editline]

Oh and actually in GMod lua conventions you should write first letter of methods uppercase. Like done on lib functions.