• Nil Value when buying perk ingame.
    3 replies, posted
I'm trying to have purchasable perks ingame. I'll explain is much as i can. So have have made the GUI for the perks. work perfectly. everything in it works with no errors [url]https://pastebin.com/UzBGK4CU[/url] Now. when i do click on the button to buy. it runs a console command going to this. [url]https://pastebin.com/ih1UtuuA[/url] But i get errors with that function. says its a nil value and perk is not bought and money does not go down. [img]http://i.imgur.com/8JAvDoi.jpg[/img]
[QUOTE=booyadiaz;52220292]I'm trying to have purchasable perks ingame. I'll explain is much as i can. So have have made the GUI for the perks. work perfectly. everything in it works with no errors [url]https://pastebin.com/UzBGK4CU[/url] Now. when i do click on the button to buy. it runs a console command going to this. [url]https://pastebin.com/ih1UtuuA[/url] But i get errors with that function. says its a nil value and perk is not bought and money does not go down. [img]http://i.imgur.com/8JAvDoi.jpg[/img][/QUOTE] It would be easier if you wrote the complete error.
It's because you are not pulling the "perk" argument into the PurchasePerk function, it should be this: [CODE]function PurchasePerk(ply, _, args) local perk = tonumber(args[1]) local cash = tonumber(ply:GetNWInt("Money")) ply:SetNWInt("Money", (cash - GAMEMODE.PlayerPerk[perk].Pricing)) GAMEMODE.PlayerPerk[perk].AddFunction(ply) GAMEMODE.SendDataToAClient(ply) [/CODE] Few suggestions though: Check if they have enough money instead of just taking it away(They could buy it at any point and go in negative money if they exploit your code, because you are checking if they have enough only on client side, remember, never trust client(side)!) Check if the perk they send you is an actual available perk before running the SetNWInt function and all the other ones. You don't need to do tonumber on the GetNWInt, it already returns a number. Make the PurchasePerk function local, pretty sure you aren't going to use it anywhere else other than as a function for the concommand.add, it's bad to just make every function global for no reason.
Thanks Newjorciks. Got it to work with that. I did fix the exploit with the buying as well.
Sorry, you need to Log In to post a reply to this thread.