Pet System help, Attempt to index nil with "Pets"

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    a Pet system. the script suppose to carry pet name and rarity to billboard

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I am new at scripting and this is for my first project so I Don’t know exactly how should I search. I tried to check other people’s pet systems but welp I didn’t understand anything.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Workspace= game:GetService("Workspace")
local ReplicatedStorage= game:GetService("ReplicatedStorage")

local EggsFolder = Workspace.Eggs
local PetModels = ReplicatedStorage.Pets

local EggConfig = require(ReplicatedStorage.Config.Eggs)

local template= script.Parent.Template
local function GetRarityColor(rarity: string)
	local color
	if rarity == "Common" then
		color= Color3.fromRGB(255,255,255)
	elseif rarity == "Uncommon" then
		color= Color3.fromRGB(83, 255, 97)
	elseif rarity == "Rare" then
		color= Color3.fromRGB(55, 98, 199)
	elseif rarity == "Legendary" then
		color= Color3.fromRGB(225, 244, 50)
	end
	return color
end
local function GeneratePet(container: Frame, petConfig: table)
	local clone = container.template:Clone()
	clone.Parent = container
	clone.Name = petConfig.Name
	clone.Visible = true
	clone.PetName.Text =petConfig.Name:gsub("_"," "	)
	clone.Rarity	.Text = petConfig.Rarity
	clone.Rarity.TextColor3 = GetRarityColor(petConfig.Rarity)
end
	
	

local function GenerateBillBoardGui(eggModel:Instance,eggConfig: table)
	local Attachment = eggModel.Egg.Attachment
	local Clone = template:Clone()
	Clone.Parent = script.Parent
	Clone.Adornee = Attachment
	Clone.Name= eggModel.Name
	for _,pet in ipairs(eggConfig.Pets) do
		GeneratePet(Clone.Frame.Container, pet)	
	end
end

GenerateBillBoardGui(EggsFolder.Basic_Egg, EggConfig.BasicEgg)

here is the Modulescript photo and explorer if you need them


If possible could you print the variable eggconfig

Just under the GenerateBillBoardGUi function

And tell me what it returns

1 Like

Like this?


Yes (charrrrrrrsksjsjzjsjskskdkdk)

1 Like

it returned nil. (sadsadsadsadasdas)

You have Basic_Egg in your module, but your trying to get BasicEgg.

image
Also you should remove the underscore in the 2000, could be an issue as well.

1 Like

it worked.I feel stupid… thanks… Really but I got another error can you help with it too?

That just means the object is not there. If you’re sure it is, try using :WaitForChild("template")?

1 Like

image

From the image, I don’t see no template in the container frame.

1 Like

yep yep I Figured out it before you reply sorry about that love you

1 Like

I am really sorry to ask another question but why this is wrong?
am I blind or forget to change something?

It’s okay, having a lot of errors in a row like this is actually a lot better than the code just not working with no errors.

Print the rarity value before those if statements. If none of those if statements run, the error happens because the function doesn’t return a color.

I didn’t understand how to print rarity beforer if statements I mean Config.rarity comes after if statements


YEAH I really feel like genius after found what you mean

So, legendary is supposed to be Legendary so the correct color should be returned. You could also fix this by using :lower() on the rarity, so it isn’t case sensitive.

print(rarity) --> LegENDARY
if rarity:lower() == "legendary" then
    -- code here runs
end
1 Like

I wish I could give you unlimited hearts. Like I literally searched corners of google just to find it. Thanks.You have my whole respect. if one day I become an devil lord I will spare your life

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