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.
[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.