Problem with tables and arrays

  1. What do you want to achieve? Keep it simple and clear!
    So i have an small problem. Instead of getting [""] i get something like that [""] = 1.
    But in this situation i need to get all arrays names not their value. Also important so no one will say me about it. It prints 5, but when luck added it looks like that [“Luck1”] = 1

  2. What is the issue? Include screenshots / videos if possible!
    After deep investigation i found what it is getting amount. So my ProductionTable[luck] become nil.
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I literally have an small script checker, but it didn’t help as i see

Get Money Code:

...
function ServerModule.GetMoney(player, Time)
	task.wait(Time)
	Income = 0
	local LuckTable = PlayerManager.GetLuckAmounts(player)
	local ProductionModule = require(script.Parent.MainModules.ProductionModule)
	for _,lucks in pairs(LuckTable) do
		print(lucks)
		print(ProductionModule[lucks])
		Income += ProductionModule[lucks] + PlayerManager.GetLuckAmounts(player, lucks)
	end
		PlayerManager.SetValue(player, "Power", PlayerManager.GetValue(player, "Power") + Income)
	HeadGUI.StatsFrame.PowerLabel = "Power: "..Suffix(PlayerManager.GetValue(player, "Power"), 2).."Amp"
	print(PlayerManager.GetValue(player, "Power"))
end
...

GetLuckAmounts code

function PlayerManager.GetLuckAmounts(player, luck)
	if luck == nil then
	return sessionData[player.UserId].LuckAmounts
	elseif luck ~= nil then
	return sessionData[player.UserId].LuckAmounts[luck]
	end
end

You should change the loop to something like this:

for key,value in pairs(LuckTable) do

then you can access both the key name and it’s value:

print(key) -- will print the key name
print(ProductionModule[key])
1 Like

Try switching your modules function from a . for a :

I already understood that thing yeah, i realised in in 11pm how to do it right lol, but anyways thanks

Bruh what would this change, for this function it wouldn’t give any result

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.