Error when trying to Clone a Part in Replicated Storage, other problems as well

Hey, Ive been having trouble for a few days now. I cant seem to Clone a Part thats suppose to be a Pet from Replicated Storage to a ViewPortFrame because it comes back as nil even though i know its there.
For context: I have similar code that instead of Cloning a Pet, it clones a Sword and that works and shows in the ViewPortFrame but when the Pet Code is in the script it limits the Sword GUI to 4 buy option when there are 11. Heres what is looks like now:


Heres what it should look like

Heres the Pets section of the GUI(The Selection button and the VPF bug out, overlap) :

Heres the Code where the problem happens(This is from a Local Script BTW):

local fakeCam = Instance.new("Camera")
fakeCam.Parent = box.VPF
local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
handle.Parent = box.VPF
box.VPF.CurrentCamera = fakeCam
fakeCam.CFrame = handle.CameraCFrame.Value
itemFrame["Item"..i].ItemName.Text = availableTools[i][1]	
local budFakeCam = Instance.new("Camera")
budFakeCam.Parent = Bbox.VPF
local handle = game.ReplicatedStorage:WaitForChild("BuddyModels"):FindFirstChild(availableBuddys[i][1].."Pet"):Clone()
handle.Parent = Bbox.VPF
Bbox.VPF.CurrentCamera = budFakeCam
budFakeCam.CFrame = handle.CameraCFrame.Value
buddyFrame["Bud"..i].BItemName.Text = availableBuddys[i][1]

dev forum 1

The Replicated Functions
local availableTools = game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
local availableBuddys = game.ReplicatedStorage:WaitForChild("GetBud"):InvokeServer()

The Script that checks for the Invoke:

 local module = {}
function module:Init()
	game.ReplicatedStorage:WaitForChild("GetTools").OnServerInvoke = function(player)
local items  = {}

for _, object in pairs(game.ServerStorage:WaitForChild("Items"):GetChildren())do
	local itemProperties = {object.Name,object.Price.Value}
	table.insert(items,itemProperties)
end
return items
end

 game.ReplicatedStorage:WaitForChild("ItemCheck").OnServerInvoke = function(player,itemName)
     if 
 game.ServerStorage.PlayerData:FindFirstChild(player.Name).Inventory:FindFirstChild(itemName) 
 then
	return true
else
   return false
   end
 end

game.ReplicatedStorage:WaitForChild("PurchaseItem").OnServerInvoke = 
function(player,itemName)
local buxs = player.leaderstats.Buxs
local item = game.ServerStorage.Items:FindFirstChild(itemName)

if item then
	--Item Exists
	if game.ServerStorage.PlayerData[player.Name].Inventory:FindFirstChild(itemName)then
		if game.ServerStorage.PlayerData[player.Name].Equipped.Value ~= itemName then
			--Currently unequipped
			game.ServerStorage.PlayerData[player.Name].Equipped.Value = itemName
			return "Equipped"
		else
			game.ServerStorage.PlayerData[player.Name].Equipped.Value = ""
			return "Unequipped"
		end
	end
	if buxs.Value >= item.Price.Value then 
		buxs.Value = buxs.Value - item.Price.Value
		local itemValue = Instance.new("ObjectValue")
		itemValue.Name = itemName
		itemValue.Parent = game.ServerStorage.PlayerData[player.name].Inventory
		
		return true
	else
		
		return "NotEnoughBuxs"
	
	end
else
	return "NoItem"
end
 end
 end
  game.ReplicatedStorage:WaitForChild("GetBud").OnServerInvoke = function(player)
    local	buditems  = {}

for _, object in pairs(game.ServerStorage:WaitForChild("Buddys"):GetChildren())do
	local buditemProperties = {object.Name,object.Price.Value}
	--print(buditemProperties,buditems,#buditems,#buditemProperties)
	table.insert(buditems,buditemProperties)
end
return buditems
 end

game.ReplicatedStorage:WaitForChild("BuddyCheck").OnServerInvoke = 
function(player,BitemName)
   if game.ServerStorage.PlayerData:FindFirstChild(player.Name).BuddyInventory:FindFirstChild(BitemName) then
	return true
else
	return false
end
end

game.ReplicatedStorage:WaitForChild("BudPurchaseItem").OnServerInvoke = 
 function(player,BitemName)
  local buxs = player.leaderstats.Buxs
  local buditem = game.ServerStorage.Buddys:FindFirstChild(BitemName)

if buditem then
	--Item Exists
	if game.ServerStorage.PlayerData[player.Name].BuddyInventory:FindFirstChild(BitemName)then
		if game.ServerStorage.PlayerData[player.Name].BuddyEquipped.Value ~= BitemName then
			--Currently unequipped
			game.ServerStorage.PlayerData[player.Name].BuddyEquipped.Value = BitemName
			return "BuddyEquipped"
		else
			game.ServerStorage.PlayerData[player.Name].BuddyEquipped.Value = ""
			return "BuddyUnequipped"
		end
	end
	if buxs.Value >= buditem.Price.Value then 
		buxs.Value = buxs.Value - buditem.Price.Value
		local itemValue = Instance.new("ObjectValue")
		itemValue.Name = BitemName
		itemValue.Parent = game.ServerStorage.PlayerData[player.name].BuddyInventory

		return true
	else

		return "NotEnoughBuxs"

	end
else
	return "NoBuddy"
end
end

return module

Try a little debugging. First can you show us exactly which line is line 386 as we can’t see line numbers. Also, add some print statements above this line and print out the variables before you get to this line. For instance, print out “i”, then print out availableTools if you use those variables in line 386. Make sure those variables contain the values you believe they should have.

1 Like

i is a number, it prints the number 4. I dont know where it got that number from because for the tools there should be 11 and for the buddys it should be 3. Also when i do
print(availableTools)
and
print(availableBuddys)
It shows what it should be.

Probably because the way its set up :

for i = 1,numberOfItems,1 do 
	if i == 1 then 
		box = item1
	else 
		
		box = item1:Clone()
		box.Name = "Item"..i
		box.Parent = itemFrame
		
		
		if (i-1) / (4*numRows) == 1 then
			-- New Row
			numRows = numRows + 1 
			box.Position = UDim2.new(PADDING_X,0,box.Position.Y.Scale,0) + UDim2.new(0,0,DROPDOWN_Y*(numRows - 1))
		else
			--Add to the X only
			box.Position = itemFrame["Item"..(i-1)].Position + UDim2.new(DROPDOWN_X,0,0,0)
				
			
	end
		
	end
	---			Buddy Item			---
for i = 1,numberOfBuddys,1 do 
		if i == 1 then 
			Bbox = budItem1
		else 

			Bbox = budItem1:Clone()
			Bbox.Name = "Bud"..i
			Bbox.Parent = buddyFrame


			if (i-1) / (4*bnumRows) == 1 then
				-- New Row
				bnumRows = bnumRows + 1 
				Bbox.Position = UDim2.new(PADDING_X,0,Bbox.Position.Y.Scale,0) + UDim2.new(0,0,DROPDOWN_Y*(bnumRows - 1))
			else
				--Add to the X only
				Bbox.Position = buddyFrame["Bud"..(i-1)].Position + UDim2.new(DROPDOWN_X,0,0,0)


				end
			end
	end

Under the Buddy Item Section, is there a way to replace the i for something else and it still represent a number?

Okay looking this over again I think the problem might be that in the first code you showed(the localscript) you have both availableTools and availableBuddys referenced with i which you don’t show where i is set or the loop where i is set. You should have 2 loops, one for the tools and one for the buddys. They shouldn’t all be in the same loop and indexed with the same variable as they differ in length.

thank you! you helped me realize my mistake. I just added an extra

end

where it should’ve ended

Now because I fixed the error. It displays 5 ImageButtons and one item is a duplicate after the other 4 are listed. On the buddy Frame, it displayed 3 of them. New Problem is that I cant Equip, Buy, or Unequip the items or the buddy.