• attempt to call method 'SteamID' (a nil value)
    3 replies, posted
[lua] function new_player( ply ) query = ( "INSERT INTO mm_items (`steamid`, `coins`)VALUES ('"..ply:SteamID().."', '50')" ) result = sql.Query(query) query1 = ( "INSERT INTO mm_skills (`steamid`, `fishing`, `building`, `chopping`, `fighting`, `ruling`)VALUES ('"..ply:SteamID().."', '0', '0', '0', '0', '0')" ) result1 = sql.Query(query) query2 = ( "INSERT INTO mm_players (`steamid`, `rank`, `warnings`, `previousbans`)VALUES ('"..ply:SteamID().."', '1', '0', '0')" ) result2 = sql.Query(query) if (result) && (result1) && (result2) then ply:ChatPrint("MM: New Account Created.") end end [/lua] [code] Timer Error: a.lua:120: attempt to call method 'SteamID' (a nil value) [/code] The following line is 120. [code] query = ( "INSERT INTO mm_items (`steamid`, `coins`)VALUES ('"..ply:SteamID().."', '50')" ) [/code] The code starts at line 118.
Can you give us your timer.Create or timer.Simple line?
[lua] function Initialize() create_shit() end function PlayerInitialSpawn( ply ) timer.Create("Steam_id_delay", 1, 1, function() SteamID = ply:SteamID() ply:SetNWString("SteamID", SteamID) timer.Create("SaveStat", 10, 0, function() saveStat( ply ) end) player_exists( ply ) end) end hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlayerInitialSpawn ) hook.Add( "Initialize", "Initialize", Initialize ) [/lua] Sorry ><
This new code doesn't appear to reference your new_player function at any point. I can see a few things else that want fixing, though. Firstly when a player first spawns you create a ten-second infinitely looping timer to save his stats. But the name is always SaveStat, so when another player joins, it'll create the timer again and overwrite the old one. For the name you might want to do "SaveStat"..ply:SteamID() - so the timer is unique for each player. On line 8 of your second code snippet you're creating a global SteamID - since you're presumably only using that in your timer function, make it local so it keeps the global table a bit cleaner. It also helps to local functions you're using as hooks - just put local before function and the functions won't needlessly go in the global table as well. In your first snippet, query, result, result1 and result2 are only being used in that function, so make them local as well.
Sorry, you need to Log In to post a reply to this thread.