tommysticks Posted November 18, 2019 Share Posted November 18, 2019 I'm trying to alter player XP using a table with this code: for i, k in pairs(Perks) do getPlayer():getXp():AddXP(Perks.k, 10); end ...and it's not working. When I print Perks.k it comes up nil, but if I print k alone it prints as the userdata from the Perks table, Sprinting as an example. And to check to see if this is the same data as Perks.Sprinting I did a quick "if k == Perks.Sprinting" and it came out true. Any insight on this would be appreciated. @RoboMat if you're still around I figure the issue is probably apparent to you. Link to comment Share on other sites More sharing options...
ethanwdp Posted November 18, 2019 Share Posted November 18, 2019 (edited) Use Perks.FromString (or Perks.fromIndex if you're iterating numerically). I don't know why, but accessing Perks like a regular table & passing it to a Kahlua function results in errors. for i, k in pairs(Perks) do local perk = Perks.FromString(i) if PerkFactory.getPerk(perk) ~= nil then getPlayer():getXp():AddXP(perk,10) end end Some of the "perks" (i.e Agility) are categories, so I'd recommend using PerkFactory.getPerk to ensure that the perk exists. Edited November 18, 2019 by ethanwdp tommysticks 1 Link to comment Share on other sites More sharing options...
tommysticks Posted November 18, 2019 Author Share Posted November 18, 2019 You’re a king. Thanks. Link to comment Share on other sites More sharing options...
tommysticks Posted November 19, 2019 Author Share Posted November 19, 2019 18 hours ago, ethanwdp said: <stuff> Thanks again bro, I spent hours yesterday messin around with this. I have an aversion to asking for help on here, but I should have just done that right away. Would have saved me some time. This does exactly what I was lookin for. ethanwdp 1 Link to comment Share on other sites More sharing options...
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