Money system help

I can’t seem to get my money system too say inefficient funds.
[lua]

function Meta:TakeCoins( int )
local coins = self:GetPData( PDataTable );
if self:GetPData( PDataTable ) < int then
print ( " inefficient funds." )
else
self:SetPData( PDataTable, self:GetPData(“Currency”) - tonumber( int ) );
RunConsoleCommand(“gc_RefreshMoney”)
end
end
[/lua]
The error I keep geting is
"
[gamemodes\ice-live\gamemode\core\server\il_moneysystem.lua:39] attempt to compare string with number"

The full script for my money system:
[lua]
local Meta = FindMetaTable(“Player”);
// Money System

– GLOBAL VARS

PDataTable = “Currency”;
NWIntTable = “Money”;


– PLAYER META

local Meta = FindMetaTable(“Player”);

– pl:SetMoney( 3 )
function Meta:SetMoney( int )
self:SetPData( PDataTable, tonumber( int ) );
self:SetNWInt( NWIntTable, tonumber( int ) )
–print( "GCUR - Set " … self:Nick() … "'s money to " … int … “.” );
end

– pl:GetMoney()
function Meta:GetMoney()
return self:GetPData( PDataTable );
end

function Meta:AddMoney( int )
self:SetPData( PDataTable, self:GetPData(“Currency”) + tonumber( int ) );

–print( "GCUR - added to " … self:Nick() … "'s money by " … int … “.” );
end

– pl:TakeMoney( 2 )
function Meta:TakeCoins( int )
local coins = self:GetPData( PDataTable );
if self:GetPData( PDataTable ) < int then
print ( " FUCK NO " )
else
self:SetPData( PDataTable, self:GetPData(“Currency”) - tonumber( int ) );
RunConsoleCommand(“gc_RefreshMoney”)
end
end

– pl:ResetMoney()
function Meta:ResetMoney()
self:SetPData( PDataTable, 0 );
self:SetNWInt( NWIntTable, 0 )
–print( "GCUR - set " … self:Nick() … “'s money to 0.” );
end

– pl:RefreshMoney()
function Meta:RefreshMoney()
self:SetMoney( self:GetMoney() )
self:SetNWInt( NWIntTable, tonumber( self:GetMoney() ) )
–print( self:Nick() … “'s money was refreshed.” )
end


– CONSOLE COMMANDS

concommand.Add(“gc_SetMoney”, function( pl, cmd, args )
pl:SetMoney( args[1] )
end)

concommand.Add(“gc_GetMoney”, function( pl )
print( "GetMoney Called : " … pl:GetMoney() )
end)

concommand.Add(“gc_AddMoney”, function( pl, cmd, args )
pl:AddMoney( args[1] )
end)

concommand.Add(“gc_TakeMoney”, function( pl, cmd, args )
pl:TakeMoney( args[1] )
end)

concommand.Add(“gc_RefreshMoney”, function( pl )
pl:RefreshMoney()
end)

concommand.Add(“gc_ResetMoney”, function( pl )
pl:ResetMoney()
end)

concommand.Add(“gc_PrintCCs”, function( pl, cmd, args )
print(“GCURRENCY CONCOMMANDS LIST:”);
print(“Command Prefix: gc_”);
print(“Command Format: command[ args[1], args[2], args[3], args[4], etc.]”);
print(“SetMoney[ amount ]”);
print(“GetMoney[ none ]”);
print(“AddMoney[ amount ]”);
print(“TakeMoney[ amount ]”);
print(“RefreshMoney[ none ]”);
print(“ResetMoney[ none ]”);
print(“PrintCCs[ none ]”);
end)
hook.Add(“HUDPaint”,“DrawMyMoney”,function()
draw.DrawText( LocalPlayer():GetNWInt( “Money” ), “ScoreboardText”, ScrW() - 20, ScrH() - 20, color_white, 2 )
end)

[/lua]

PData uses sql I guess… afaik sql returns everything as a string, so you gotta turn that string into a number.

[lua]if (tonumber(self:GetPData( PDataTable )) < int) then[/lua]

Thank you i t work perfectly now.

You may also want to check if the data exists, if it doesn’t, it will return nil and will break.

function Meta:GetMoney()
return self:GetPData( PDataTable ) or 0;
end

probably a stupid question or a question you may not know the answer to but can’t these money system addon be linked to a SQL database? Sorry i’m not 100% sure if the game was able to do that so I ask.

It surely can, there’s a few modules as well as SQLite that is built in.

Yeah i thought so. maybe more convenient to have it hooked to a database, especially if its to be used with a store mod and vendors.

It’s more useful on a database if you plan to have data over multiple servers or display a stats page on a website or something.

yeah thats what i was getting to