Problem with inventory system

i have 3 rarity type caterpillars from the shop that u can buy. in the inventory what’s happening is, in the viewportframe, the models names have the correct rarity type but it only clones the common caterpillar model for every slot. so if i had a rare caterpillar, the name of the model would be “rare caterpillar” but the visual model is a common caterpillar. :triumph:

code:

local caterpillarModels = {
	common_caterpillar = dataFolder:FindFirstChild("common_caterpillar"),
	uncommon_caterpillar = dataFolder:FindFirstChild("uncommon_caterpillar"),
	rare_caterpillar = dataFolder:FindFirstChild("rare_caterpillar"),
}

function module.createSlots()
	local totalval = 0

	--count slots to make
	for _, int in pairs(invfolder:GetChildren()) do
		if int:IsA("IntValue") and int.Value > 0 then

			if open == true then
				for i = 1, int.Value do
					local model = caterpillarModels[int.Name]
					print(model.Name)
					local slotclone = slotButton:Clone()
					slotclone.Parent = scrollingframe
					local thumbnail = slotclone.thumbnail
					local cam = Instance.new("Camera")
					cam.Parent = thumbnail

					thumbnail.CurrentCamera = cam
					
					if model then
						print("Found model for " .. int.Name .. ": " .. model.Name)
					else
						print("No model found for: " .. int.Name)
					end
					
					local modelClone = model:Clone()
					modelClone.Parent = thumbnail
					
					local modelCF = modelClone:GetBoundingBox()
					cam.CFrame = CFrame.new(modelCF.Position + Vector3.new(35,0,0)) * CFrame.Angles(0, math.rad(90), 0)
				end
			end
		end
	end

problem:

I’m not sure, But I’m pretty confident the issue is here.

for _, int in pairs(invfolder:GetChildren()) do--these are all the caterpillars, right?
		if int:IsA("IntValue") and int.Value > 0 then

			if open == true then
				for i = 1, int.Value do--what is this doing, can you explain?

Can you explain what this code does?

1 Like

hey man, thanks for your help!

so ive got this InventoryFolder in each player which has intvalues. that stores how many of each item they have from the shop. im iterating thru the folder so i can work with the different intvalues. if the intValue’s value is more than 0 then the player has something, i want it to create slots; that’s if the inventory is open.

hopefully that makes sense.

the inventory folder:
image

1 Like

Okay, well first of all, You don’t need this.

local caterpillarModels = {
	common_caterpillar = dataFolder:FindFirstChild("common_caterpillar"),
	uncommon_caterpillar = dataFolder:FindFirstChild("uncommon_caterpillar"),
	rare_caterpillar = dataFolder:FindFirstChild("rare_caterpillar"),
}

when you search for the caterpillars, instead of

local model = caterpillarModels[int.Name]

do

local model = dataFolder:FindFirstChild(Int.Name),

Do determine where the issue is, right after

	for i = 1, int.Value do

Could you put a

print(Int.Name)

to determine if the different types of caterpillar are being chosen, or if the code is bugging around there?

1 Like

tytyty i put in this debugging statement within where you said.

					print("Model name: ".. model.Name,
						"IntValue Name: "..int.Name
					)

its got the name correct and the int value as well. this is my current inventory but it clones only the common caterpillar. :triumph:
image

Okay, that means that the issue is with the Frame cloning at the bottom of the code.

Is the slotclone.thumbnail image the common caterpillar by default? (If you look right now, without playing the game, is the current thumbnail the common caterpillar?)

Is the slotclone an ImageButton?
if it is, you can’t assign images with the camera. You would need different images uploaded to the game.

If it is a ViewportFrame, can you confirm that all the models have different positions, so that they don’t overlap?

1 Like

so the thumbnail is actually a viewportframe. nope its just blank like this:

the slot button is actually a text button so thats all good.

yes. this is what they look like in the workspace

Huh, confusing. Okay, when you play the game, can you go into 1 of the slots for one of the incorrectly displayed caterpillars, and check that the model in there is the correct model, and that there is noting else in there?

Can you add a print(modelClone) to confirm that the clone is of the intended model?

Honestly at this point, I would assume that this isn’t a bug in the code, I would just assume that there is just something incorrectly named, or a common caterpillar in the wrong spot.

1 Like

it is very confusing thats mb.

the models are correct, there’s nothing else in there. each camera seems to be at the same caterpillar or something.

yup it is.

yeah its a strange one. i’ll find some similar resources to see if i can fix it. thank you so much for ur help missile, hope u have a great day mate!!!

1 Like