DotFrank Posted April 29, 2017 Share Posted April 29, 2017 Hi guys, i have a problem comparing getPlayerMoney() with price, if i dont use tonumber(price) the error is 'attemp to compare string with number' and if i use tonumber(price) then the error is 'attemp to compare nil with number'. This problem is only comparing, if I do not use the condition server-side gives me the weapon. function onBuyWeapon() local itemSelected= guiGridListGetSelectedItem(list) if itemSelected ~= -1 then local weaponName = guiGridListGetItemText (list,itemSelected,column_arma) local ammo = guiGridListGetItemText(list,itemSelected,column_balas) local price = guiGridListGetItemText(list,itemSelected,column_precio) if getPlayerMoney() >= price then triggerServerEvent("onBuyWeapon",getLocalPlayer(),weaponName,ammo,price) end end end Link to comment
NeXuS™ Posted April 29, 2017 Share Posted April 29, 2017 Quote Note: The amount may vary between the server and client, you shouldn't trust the client side value to always be accurate. I dont think you should check if the player has enough money on client-side. Link to comment
DotFrank Posted April 29, 2017 Author Share Posted April 29, 2017 I already used it on server side too, same mistake. --server-side if getPlayerMoney(source) >= price then -- attempt to compare string with number. I if use tonumber(price) the error is => attempt to compare nil with number giveWeapon(source,weaponID,ammo) -- without the condition it gives me the weapon end Link to comment
NeXuS™ Posted April 29, 2017 Share Posted April 29, 2017 Try debugging the script. Add outputChatBox(price) above the if statement on your server-sided script. Link to comment
DotFrank Posted April 29, 2017 Author Share Posted April 29, 2017 it prints me the price Link to comment
NeXuS™ Posted April 29, 2017 Share Posted April 29, 2017 (edited) Can you do a screenshot of it? It's maybe non-convertible to number. Edited April 29, 2017 by NeXuS™ 1 Link to comment
DotFrank Posted April 29, 2017 Author Share Posted April 29, 2017 its prints but the problem keeps in the condition. Link to comment
NeXuS™ Posted April 29, 2017 Share Posted April 29, 2017 Try this. if getPlayerMoney(source) >= tonumber(string.sub(price, 2)) then -- attempt to compare string with number. I if use tonumber(price) the error is => attempt to compare nil with number giveWeapon(source,weaponID,ammo) -- without the condition it gives me the weapon end 1 Link to comment
DotFrank Posted April 29, 2017 Author Share Posted April 29, 2017 it works, thank you NeXuS! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now