In my LocalScript I get this weird error:
16:27:41.566 - Players.Player1.PlayerGui.Console2.Console.Input.LocalScript:39: attempt to perform arithmetic on field 'x' (a nil value)
But I don't know why...
My code:
local yesTime = 5 local yes = false local chanceIP, chanceVirus, chanceFirewall, chanceTrace, chanceNetwork, chanceRemote, chancePhysical, chanceStealth, chanceLocal, chanceCracker, chanceLevel local Skills = { ["IP"] = 1, ["virus"] = 1, ["firewall"] = 1, ["trace"] = 1, ["network"] = 1, ["remote"] = 1, ["physical"] = 1, ["stealth"] = 1, ["Local"] = 1, ["cracker"] = 1, ["level"] = 1 } local function chance(x) local rndmNeedWork = math.random(50) rndmNeedWork = rndmNeedWork * Skills.x - Skills.x if rndmNeedWork > 30 then yes = true wait(yesTime) yes =false end end while true do wait(0.1) chance("IP") end
All help appreciated!
The script is trying to access the actual child of Skills called x, for example:
Skills.x = nil
, so indexing it will return nil
. To find a index in a table using it's key, you need to index it like this:
Skills[x]
Not:
Skills.x
Also, when defining the key of something, if you want it to be indexed by an unknown value (x, for example, which can be any string), you need to make sure the indexing is done like this:
array["keyString" or variableName]
And not like this:
array.keyString or array.variableName
So, instead of doing Skills.x
, do:
Skills[x] = Skills[x] + Skills[x] -- or whatever you wanted to do with it
Hope I helped!
~TDP