• Money System Problem
    5 replies, posted
So, I'm trying to make a menu where when you buy something it takes money away from you and If you don't have enough money you can't buy it. [LUA] function player_meta:TakeMoney( amount ) if self:HasMoney( amount ) then self:SetPData( MoneyIdentity, self:GetPData( MoneyIdentity ) - amount ); self:SetNWInt( MoneyIdentity, self:GetPData( MoneyIdentity ) ); end; end; function player_meta:HasMoney( amount ) if self:GetPData( MoneyIdentity ) >= amount then -- Line 34 return true; else return false; end; end; [/LUA] The only problem is that If I don't have enough money it still lets me buy the item. This is the Error I have: [CODE] moneysystem.lua:34] attempt to compare number with string [/CODE] If someone could help me out that would be great.
which line is 34 in here?
[b][url=http://wiki.garrysmod.com/?title=G.tonumber]G.tonumber [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[CODE] if self:GetPData( MoneyIdentity ) >= amount then -- Line 34 [/CODE] is line 34 Also, can you explain how you would use tonumber? As you can tell I'm not the best with Lua.
[QUOTE=I Fail At Lua;25112343][CODE] if self:GetPData( MoneyIdentity ) >= amount then -- Line 34 [/CODE] is line 34 Also, can you explain how you would use tonumber? As you can tell I'm not the best with Lua.[/QUOTE] [lua] if(20 > tonumber("19")) then print("Yay") end [/lua] [lua]if tonumber(self:GetPData( MoneyIdentity )) >= amount then[/lua]
Oh, I get it now, Thank you very much
Sorry, you need to Log In to post a reply to this thread.