Passing through a table

So i am creating a stats system that has a table that gives players all their basestats.
local baseStats =
{

	Health = 100;
	Mana = 1000;
	MaxMana = 1000;
	Defense = 5;
	Strength = 10;
	Level = 1;
	Exp = 0;
	ExpNeed = 100;
	Points = 0;
	MaxLevel = 20;
	
}

I am having a problem with passing through the table for example:
warn(“Player has no data”)
for i, data in ipairs(PlrStats:GetChildren()) do
data.Value = baseStats[i]
print(data.Name,“:”,data.Value)
end

I keep getting Null for baseStats[i]. but it should be getting the values from the basestats array

Try using in pairs() instead of in ipairs().

1 Like

Your problem is that baseStats does not use integer keys, it uses string keys such as ‘Health’ and ‘Strength’, so baseStats[1] is nil but baseStats[“Points”] is 0.

If you can’t find a solution, show me the PlrStats folder and I will find one for you.

1 Like

I just tried this it did the same thing

I think you are right about that because baseStats.Health works so how would i be able to go through the table with strings? Also heres pic of plrstats when player loads in

plrstats

This may be what you are looking for:

local baseStats =
	{

		Health = 100;
		Mana = 1000;
		MaxMana = 1000;
		Defense = 5;
		Strength = 10;
		Level = 1;
		Exp = 0;
		ExpNeed = 100;
		Points = 0;
		MaxLevel = 20;

	}


for statName, statValue in pairs(baseStats) do
	childStats = PlrStats:GetChildren()
	childStats[statName].Value = statValue
end
3 Likes

That did it lets goo. Thank you!!