So I am trying to get the number of values in this dictionary/table but I can’t, so I just put the number to 1000 and would check if it is nil. Sadly, it is nil and I have no clue why.
I need this to create a textbutton for every value in “Ducks” so the player can check what badges they need and so on.
1st script (Nil error)
local System = require(game:GetService("ReplicatedStorage"):FindFirstChild("MainModule"))
local Info = System.Ducks
local BadgeService = game:GetService("BadgeService")
local function getIcon(BadgeId)
local success, badge = pcall(function()
return BadgeService:GetBadgeInfoAsync(BadgeId)
end)
if success then
return badge
else
end
end
for i = 1, 1000 do
print("1")
print(Info[1]) -- It prints nil :((((((((((((
if Info[i] ~= nil then
print("2")
local badge = getIcon(Info[i].BadgeId)
local Button = script.ImageButton:Clone()
Button.Name = Info[i]
Button.TextLabel.Text = Info[i].Name
pcall(function()
Button.Image = "rbxassetid://"..badge
Button.Parent = script.Parent.Parent.Parent
end)
else
break
end
end
2nd mainmodule:
local Ducks = {}
local BadgeService = game:GetService("BadgeService")
Ducks["Ducks"] = {
["Duck"] = {
Name = "Duck";
Description = "Your average duck. :)";
Hint = "At spawn";
Stars = 1;
Color = {255, 255, 0};
BadgeId = 2124823088;
},
["PirateDuck"] = {
Name = "Pirate Duck";
Description = "Weird, eh?";
Hint = "Near the seas";
Stars = 1;
Color = {0, 0, 0};
BadgeId = 2124823089;
},
["DominusDuck"] = {
Name = "Dominus Duck";
Description = "A very rich duck!";
Hint = "Up in the sky";
Stars = 3;
Color = {189, 243, 255};
BadgeId = 2124824184;
},
}
Ducks["StarSystem"] = {
["1"] = {
Info = "Easy difficulty";
},
["2"] = {
Info = "Normal difficulty";
},
["3"] = {
Info = "Hard difficulty";
},
["4"] = {
Info = "Insanely hard difficulty";
},
["5"] = {
Info = "0.05% of people can find these ducks";
},
}
I don’t think I am doing this correctly. Please help!
In module scripts, you need to return something, and from what I can infer you’re not returning anything. To fix your problem all you have to do is simply add a return Ducks to the end of the module and instead of referencing Info as System.Ducks, it’ll simply just be System as Ducks is the returned value.
Hey,
You could put a wait at the start of the script, before the i = 1, 1000 thing:
local System = require(game:GetService("ReplicatedStorage"):FindFirstChild("MainModule"))
local BadgeService = game:GetService("BadgeService")
local function getIcon(BadgeId)
local success, badge = pcall(function()
return BadgeService:GetBadgeInfoAsync(BadgeId)
end)
if success then
return badge
else
end
end
repeat wait() until System.Ducks[1] -- Add this in!
local Info = System.Ducks --This might help as well
for i = 1, 1000 do
print("1")
print(Info[1]) -- It prints nil :((((((((((((
if Info[i] ~= nil then
print("2")
local badge = getIcon(Info[i].BadgeId)
local Button = script.ImageButton:Clone()
Button.Name = Info[i]
Button.TextLabel.Text = Info[i].Name
pcall(function()
Button.Image = "rbxassetid://"..badge
Button.Parent = script.Parent.Parent.Parent
end)
else
break
end
end
I dont use module scripts at all, so I may be completely wrong.
BUT it may be worth a try
Addtionally, you could try re-stating the value of ducks after the wait