TapsoNNN
(TapsoNNN)
February 19, 2021, 10:29am
1
Hello Everyone,
I am trying to make a Round System by Spawning Enemies with a for loop but the problem is i cant get my number what i defined by a local variable from a Module
Module Script
local module = {
["0"] = {
["Zombie"] = 5,
["Zombie2"] = 5,
},
["1"] = {
["Zombie"] = 0,
["Zombie2"] = 10,
}
}
return module
Server Script
local RoundCount = plr:FindFirstChild("leaderstats"):FindFirstChild("Round")
print(RoundConfig[RoundCount.Value].Zombie) -- Error (attempt to index nil with 'Zombie')
if i Print only Round Count its a “0”
FindFirstChild(“Round”) is a IntValue
1 Like
Try doing [0] instead of [“0”]. I believe roundcount.Value is a number value while the table you made uses string numbers as keys.
1 Like
TapsoNNN
(TapsoNNN)
February 19, 2021, 10:35am
3
you are right!
can i change the module that i have numbers instead od strings numbers or do i have to Change RoundCount toString?
jut get rid of the keys all together so its something like,
local module = {
{["Zombie"] = 5,["Zombie2"] = 5,},
{["Zombie"] = 0,["Zombie2"] = 10,},
}
return module
This will make it so it’s an numeric array and assign the indexes for you but keep in mind roblox starts from 1 so to get the first value just do
RoundCount[1]
1 Like
shabman
(shab)
February 19, 2021, 10:51am
5
Since your keys are strings it’s trying to index with an integer. Since there is no integer keys, the result is nil.
1 Like
Jxl_s
(Jxl_s)
February 19, 2021, 12:19pm
6
In your case, since the index in your table are strings, you would need to do
print(RoundConfig[tostring(RoundCount.Value)].Zombie)
2 Likes