Error attemp to nil with value

Hello how i can fix the error in my egg code
code:

local RS = game.ReplicatedStorage
local Config = require(RS.Pets.Eggs)
local Models = RS.Pets.Models
local CurrentTarget = script.Parent.CurrentTarget
local CostLabel = script.Parent.CostLabel
local PetsFrame = script.Parent.PetsFrame

function resetFrame()
	for _, Slot in pairs(PetsFrame:GetChildren()) do
		if Slot.Name ~= "Shadow" then
			for _, Item in pairs(Slot.PetView:GetChildren()) do
				Item:Destroy()
			end
			Slot.Percentage.Text = ""
			Slot.Rarity.Text = ""
			Slot.ImageColor3 = Color3.fromRGB(25, 25, 25)
		end
	end
end

CurrentTarget:GetPropertyChangedSignal("Value"):Connect(function()
	if CurrentTarget.Value ~= "None" then
		local Egg = Config[CurrentTarget.Value]
		local Cost = Egg.Cost
		local Currency = Egg.Currency
		local CurrencyImage = RS.Pets.Settings:FindFirstChild(Currency.."Image").Value
		local Counter = 0
		local Pets = {}
		for _, Pet in pairs(Egg.Pets) do
			Pets[#Pets + 1] = {
				Name = Pet.Name,
				Type = Pet.Type,
				Rarity = Pet.Rarity,
				Secret = Pet.Secret
			}
			Counter = Counter + Pet.Rarity
		end
		CostLabel.CurrencyImage.Image = CurrencyImage
		CostLabel.TextLabel.Text = Cost
		table.sort(Pets,
			function(a, b)
			return a.Rarity > b.Rarity
		end
		)
		if Currency ~= "R$" then
			script.Parent.BuyButtonR.Visible = true
			script.Parent.BuyButtonT.Visible = true
			script.Parent.BuyButtonE.Size = script.Parent.BuyButtonR.Size
		else
			script.Parent.BuyButtonR.Visible = false
			script.Parent.BuyButtonT.Visible = false
			script.Parent.BuyButtonE.Size = script.Parent.CostLabel.Size
		end
		resetFrame()
		for i, v in pairs(Pets) do
			if v.Secret == false then
				local PetName = v.Name
				local PetModel = Models:FindFirstChild(PetName):FindFirstChild(v.Type):Clone()
				local Slot = PetsFrame:FindFirstChild("Slot"..i)
				local Viewport = Slot.PetView
				local Percentage = math.floor((v.Rarity / Counter) * 10000) / 100
				local Rarity = Models:FindFirstChild(PetName).Settings.Rarity.Value
				local RarityColor = RS.Pets.Rarities:FindFirstChild(Rarity).Color.Value
				local Camera = Instance.new("Camera", Viewport)
				local Pos = Vector3.new(0, 0, 0)
				Viewport.CurrentCamera = Camera
				PetModel:SetPrimaryPartCFrame(CFrame.new(Pos))
				PetModel.Parent = Viewport
				Slot.Percentage.Text = Percentage.."%"
				Slot.Rarity.Text = Rarity
				Slot.Rarity.TextColor3 = RarityColor
				Slot.ImageColor3 = Color3.fromRGB(55, 55, 55)
				spawn(function()
					local rot = 180
					while wait() do
						if PetModel.Parent ~= nil then
							Camera.CFrame = CFrame.Angles(0, math.rad(rot), 0) * CFrame.new(Pos + Vector3.new(0, 0, 3), Pos + Vector3.new(0, 0, 0))
							rot = rot + 1
						else
							break
						end
					end
				end)
			end
		end
	else
		resetFrame()
	end
1 Like

My best bet is that Settings:FindFirstChild(Currency.."Image") is equal to nil, which means the child named Currency.."Image" doesn’t exist inside Settings when the code runs.

1 Like

thank you now i will try fix my code.

Could you list which line the error is at? It could help a lot in solving your issue-

Ok it say line 26 (i forgot to put this in my text sorry)

My guess on the issue is the same as PAGO

hi i fixed the nil value thank you now my system work

1 Like