Turbe$Z Posted May 8, 2017 Posted May 8, 2017 function buyWeapon(thePlayer, command) local mycoins = exports.coinsystem:getPlayerCoin(thePlayer) if (mycoins >= 1) then giveWeapon(thePlayer, 31, 2000) exports.coinsystem:takePlayerCoin(thePlayer, prize) outputChatBox("you bought a M4.", thePlayer, 0, 255, 0, false) else outputChatBox("you don't have enough coins!", thePlayer, 255, 0, 0, false) end end addCommandHandler("buyw", buyWeapon) i got this error: xy.lua:17: attempt to compare number with nil
SheriFF Posted May 8, 2017 Posted May 8, 2017 Please post the full script because, for example, prize is not declared Second, you don't have line 17 in your posted script Please tell us what the command is supposed to do( how it should work )
Turbe$Z Posted May 8, 2017 Author Posted May 8, 2017 4 minutes ago, *BeaT* said: Please post the full script because, for example, prize is not declared Second, you don't have line 17 in your posted script Please tell us what the command is supposed to do( how it should work ) This is the full code, sorry, line 3
aka Blue Posted May 8, 2017 Posted May 8, 2017 Uou get this error because the Quote exports.coinsystem:getPlayerCoin(thePlayer) Export, returns nil. So you can try this: function buyWeapon( player, command ) local p_coins = exports.coinsystem:getPlayerCoin( player ) if tonumber( p_coins ) >= 1 then giveWeapon(player, 31, 2000) exports.coinsystem:takePlayerCoin(player, prize) outputChatBox("you bought a M4.", player, 0, 255, 0, false) else outputChatBox("you don't have enough coins!", player, 255, 0, 0, false) end end 1
Turbe$Z Posted May 8, 2017 Author Posted May 8, 2017 9 minutes ago, aka Blue said: Uou get this error because the Export, returns nil. So you can try this: function buyWeapon( player, command ) local p_coins = exports.coinsystem:getPlayerCoin( player ) if tonumber( p_coins ) >= 1 then giveWeapon(player, 31, 2000) exports.coinsystem:takePlayerCoin(player, prize) outputChatBox("you bought a M4.", player, 0, 255, 0, false) else outputChatBox("you don't have enough coins!", player, 255, 0, 0, false) end end working with command, but with button, doesn't working, why? addEvent( "m4", true ) addEventHandler( "m4", root, function () local p_coins = exports.coinsystem:getPlayerCoin(player) if tonumber( p_coins ) >= 400 then giveWeapon(player, 31, 2000) exports.coinsystem:takePlayerCoin(player, 400) outputChatBox("you bought a M4.", player, 0, 255, 0, false) else outputChatBox("you don't have enough coins!", player, 255, 0, 0, false) end end ) i got this error: xy.lua:3: attempt to compare number with nil
aka Blue Posted May 8, 2017 Posted May 8, 2017 Because you use a player argument but its not defined. ¿Understand?. When you trigger to server, take sure you send the getLocalPlayer in the server too, something like this, see: -- Client triggerServerEvent( "m4", resourceRoot, getLocalPlayer( ) ) -- Server addEvent( "m4", true ) addEventHandler( "m4", root, function ( player ) local p_coins = exports.coinsystem:getPlayerCoin(player) if tonumber( p_coins ) >= 400 then giveWeapon(player, 31, 2000) exports.coinsystem:takePlayerCoin(player, 400) outputChatBox("you bought a M4.", player, 0, 255, 0, false) else outputChatBox("you don't have enough coins!", player, 255, 0, 0, false) end end ) 1
Turbe$Z Posted May 8, 2017 Author Posted May 8, 2017 1 minute ago, aka Blue said: Because you use a player argument but its not defined. ¿Understand?. When you trigger to server, take sure you send the getLocalPlayer in the server too, something like this, see: -- Client triggerServerEvent( "m4", resourceRoot, getLocalPlayer( ) ) -- Server addEvent( "m4", true ) addEventHandler( "m4", root, function ( player ) local p_coins = exports.coinsystem:getPlayerCoin(player) if tonumber( p_coins ) >= 400 then giveWeapon(player, 31, 2000) exports.coinsystem:takePlayerCoin(player, 400) outputChatBox("you bought a M4.", player, 0, 255, 0, false) else outputChatBox("you don't have enough coins!", player, 255, 0, 0, false) end end ) thanks
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