• attempt to index a string value with bad key ('SteamID')
    2 replies, posted
Im having an issue with this database thing im writing. I got suggested to do it in JSON but I dont know why this error occurs (Could be a JSON thing). To my knowledge its saying that ply is apart of the string? Please help me out with this if anyone knows what I have done wrong. This is the error [ERROR] lua/includes/extensions/player_auth.lua:82: attempt to index a string value with bad key ('SteamID' is not part of the string library) 1. error - [C]:-1 2. __index - lua/includes/extensions/string.lua:297 3. v - lua/includes/extensions/player_auth.lua:82 4. Run - lua/includes/modules/hook.lua:84 This is the serverside file. hook.Run("PlayerInitialSpawn", "ranchtrackerfirstjoin", function(ply) ply.AdminJoinTime = os.time() end) hook.Run("PlayerDisconnected", "OnLeave", function(ply)    if not ply:IsPlayer() or ply:IsValid() then return end     local Totaltime = os.time() - ply.AdminJoinTime     if file.Exists("timedata.txt", "DATA") then         local timeData = util.JSONToTable(file.Read("timedata.txt", "DATA"))         if timeData[ply:SteamID()] == nil then             timeData[ply:SteamID()] = {}             timeData[ply:SteamID()].weekly = Totaltime             timeData[ply:SteamID()].allTime = Totaltime         else             timeData[ply:SteamID()].weekly = timeData[ply:SteamID()].weekly + Totaltime             timeData[ply:SteamID()].allTime = timeData[ply:SteamID()].allTime + Totaltime         end         file.Write("timedata.txt", util.TableToJSON(timeData))     else         file.Write("timedata.txt", util.TabletoJSON({}))     end end)
There's a small problem there, you're doing on the first line of the PlayerDisconnected hook if not ply:IsPlayer() or ply:IsValid() then return that'd be the same as if (not ply:IsPlayer()) or ply:IsValid() then return end which would cause the script to fail there I believe Now, what line is actually line 82? And when you get the timeData you should put at the end 'or {}' in case the timedata.txt file doesn't exist, which would just make timeData nil and would lead to errors I believe
this is the player auth error file hook.Add("PlayerInitialSpawn", "PlayerAuthSpawn", function(ply)     local steamid = ply:SteamID()          if game.SinglePlayer() or ply:IsListenServerHost() then         ply:SetUserGroup("superadmin")         return     end          if SteamIDs[steamid] == nil then         ply:SetUserGroup("user")         return     end starting at line 80 ending at 91
Sorry, you need to Log In to post a reply to this thread.