Script prints out nil

Also just wanna test one more thing:

print the System variable

local System = require(game:GetService("ReplicatedStorage"):FindFirstChild("MainModule"))

print(System) 

local Info = System.Ducks

Just to see if it actually requires the module.

1 Like

It does require the module because when I get the table name it works perfectly fine.

Not a studio bug, tested it in game aswell. :frowning:

1 Like

Also might I ask, Is the Info Variable ~= nil? if not you might wanna add a for loop instead of indexing.

Try printing the Info[1] exactly after requiring it?

Info is not nil, if i do print(Info) it returns the table

1 Like

Could be something to do with that. Ill look into it

Already tried printing it, returns nil.

Yes, but the values inside of it do. I’m wondering if its because the module script has the same [] as the [i] does and thats why its messing it up?

i think i may have found a way to do this!
lemme paste the code here

2 Likes

It breaks the loop if it is == to nil, and it is.

Try this code!

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

print(Info)

for i, v in pairs(Info) do
	print(i)
	print(v)
	local badge = getIcon(v.BadgeId)
	local Button = script.ImageButton:Clone()
	Button.Name = v
	Button.TextLabel.Text = v.Name
	pcall(function()
		Button.Image = "rbxassetid://"..badge
		Button.Parent = script.Parent.Parent.Parent
	end)
end
4 Likes

When you define the table, you use strings as indexes. You have Ducks.Ducks.Duck, which is tbh slightly confusing, which is probably what led to this.

Then you look for the item in index 1 in Ducks.Ducks, which doesn’t exist. It therefore correctly prints nil. Note that you do have Ducks.StarSystem but even there the index is a string “1”.

Good luck!

i prints the name of the value! Thank you. :slight_smile:

1 Like

As @Nonaz_jr said there might be a slight confusion within the module so I suggest you changing the Module variable table name to:

local Info = {} 
1 Like

Can you tell what v print out?

I changed it to Duckss.Ducks.Duck.
I don’t mind it.

1 Like

v doesn’t print anything unless I do v.Name or v.Description.

1 Like

Oh okay then! Hope you’ll be successful on your project! Good luck!

1 Like

Thank you all for helping me! :slight_smile:

2 Likes