Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Table not working?

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

1 comment

0

The issue is that level.Value is a number, and therefore level.Value[1] is invalid.

1 answer

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.

2 comments

0

Nevermind, it's still not working. Thanks for the help though.

0

The error has changed though, to: https://gyazo.com/277f7654603f31137343c9cf359d5d91

This discussion is preserved as it was. New answers, comments, and votes are closed.