You could try something like this:
[lua]-- To make this all happen, we’re going to use a thing called GLON.
– GLON (Garry’s Mod Object Notation) is a way of storing tables as strings.
– Make the file if it doesn’t exist
if not file.Exists(“kills.txt”) then file.Write(“kills.txt”,glon.encode({})) end
– Write a player’s kills to a file
local function SaveKills(ply)
-- We use glon to decode the text from the kills.txt file
local data = glon.decode(file.Read("kills.txt"))
-- To store the data, the player's steamID is the key, and the kills is the value
data[ply:SteamID()] = ply:Frags()
-- You write the file after encoding the data with glon
file.Write("kills.txt",glon.encode(data))
end
– Get the kills a player has saved
local function GetKills(ply)
-- We use glon to decode the text from the kills.txt file
local data = glon.decode(file.Read("kills.txt"))
return data[ply:SteamID()]
end
– To put this to use, we could make concommand that prints their saved kills
local function PrintKills(ply)
-- Get the kills and print it to their chat
ply:ChatPrint("You had " .. GetKills(ply) .. " kills on this server last time.")
end
– Make the concommand
concommand.Add(“PrintKills”,PrintKills)[/lua]