Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Table not working?

Asked by 8 years ago
local values = {}

values[1]={ xp_requirement=200 } --Make a table in a table, containing all the values
--Nothing else needed here, as you never level up to level 1

values[2]={ xp_requirement=450, cash_bonus=200, maxhp_bonus=0 }

while wait(3) do
    local level = script.Parent.Parent.Parent.TextLabel.Crisps
    local experience = script.Parent.Parent.Parent.TextLabel.Chocolate
    if experience.Value >= values[level.Value[1]] then -- possible solution
        level.Value = level.Value + 1
        cash = cash + values[level.Value[2]]
    end
end

I've been trying to make a level up script which rewards upon level up using tables, however, when it runs in game, nothing happens and I get the following error in console: https://gyazo.com/f7aa075107da11989da8e6dd16ca5d1b

0
The issue is that level.Value is a number, and therefore level.Value[1] is invalid. User#6546 35 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

I think I have the solution. What is happening is that the value for level is not a table. Without knowing your hierarchy, it seems to me that crisps is a number or int value. What is happening is your are trying to use the number as a table, which is what causes your error. To fix it, I would change line 11 to:

if experience.Value >= values[level.Value].xp_requirement then

That should work, from what I can gather from your code. I hope this helps.

0
Nevermind, it's still not working. Thanks for the help though. coolyoshipower 42 — 8y
0
The error has changed though, to: https://gyazo.com/277f7654603f31137343c9cf359d5d91 coolyoshipower 42 — 8y
Ad

Answer this question