Only one item being added to a folder

This is a support category for asking questions about how to get something done on the Roblox websites or how to do something on Roblox applications such as Roblox Studio.

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!
    I’m making a fishing game, and use this ModuleScript to add my fish to a folder in ReplicatedStorage.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Fishes = ReplicatedStorage.Assets.Fishes

local FishMod = {}

FishMod.Places = {
	["Starter Island"] = {
		
	},
}

FishMod.Fishes = {
	Mackerel = {
		name = "Mackerel",
		place = FishMod.Places["Starter Island"],
		
		attributes = {
			minWeight = {
				name = "minWeight",
				val = 275
			},
			maxWeight = {
			name = "maxWeight",
			val = 350
			},
		},
		
		Salmon = {
			name = "Salmon",
			place = FishMod.Places["Starter Island"],

			attributes = {
				minWeight = {
					name = "minWeight",
					val = 1200
				},
				maxWeight = {
					name = "minWeight",
					val = 2300
				}
			},
		}
	}
}

function FishMod:CreateFishes()
	for _, fish in pairs(FishMod.Fishes) do
		if not Fishes:FindFirstChild(fish.name) then
			local FishVal = Instance.new("StringValue")
			FishVal.Name = fish.name
			FishVal.Value = fish.name
			
			for _, attribute in pairs(fish.attributes) do
				local attrVal = Instance.new("NumberValue")
				attrVal.Name = attribute.name
				attrVal.Value = attribute.val
				attrVal.Parent = FishVal
			end
			
			FishVal.Parent = Fishes
		end
	end
end

return FishMod

Yes, the function is being called in another script and the module has been required properly.

  1. What is the issue? Include screenshots / videos if possible!
    For some reason only one is being added, or only the first one is being added.
    There are no errors in the output.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried rewriting the table instead of copy pasting the same fish and editing it.

Other Details:
The part of another script its being called from:

local function playerAdded(player: Player)
	local character = player.Character or player.CharacterAdded:Wait()
	local loaded = QueueLoader.Initialize(player)
	if loaded then
		
		FishMod:CreateFishes()
		
		for _, rod in Rods:GetChildren() do
			if rod:WaitForChild("OnStart").Value then
				if player.Data.EquippedRod.Value ~= rod.Name then
					player.Data.EquippedRod.Value = rod.Name
					
					rod = rod:Clone()
					rod.Parent = character
				end
			end
		end
	else
		player:Kick("Modules failed to load")
	end
end

Players.PlayerAdded:Connect(playerAdded)

I will be very grateful for anyone who can help me resolve the bug, thanks for reading.

1 Like

When you collapse the fishes table in Studio, notice how it only shows Mackeral?
image

You’ve missed a closing bracket somewhere, which is causing Salmon to become a value within Mackeral.
Adding another closing bracket between the mackeral and salmon (and adding a comma as well) has both fish show up correctly:
image

Updated Code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Fishes = ReplicatedStorage.Assets.Fishes
local FishMod = {}
FishMod.Places = {
	["Starter Island"] = {

	},
}
FishMod.Fishes = {
	Mackerel = {
		name = "Mackerel",
		place = FishMod.Places["Starter Island"],

		attributes = {
			minWeight = {
				name = "minWeight",
				val = 275
			},
			maxWeight = {
				name = "maxWeight",
				val = 350
			},
		},
	},

	Salmon = {
		name = "Salmon",
		place = FishMod.Places["Starter Island"],
		attributes = {
			minWeight = {
				name = "minWeight",
				val = 1200
			},
			maxWeight = {
				name = "minWeight",
				val = 2300
			}
		},
	}
}


function FishMod:CreateFishes()
	for _, fish in pairs(FishMod.Fishes) do
		if not Fishes:FindFirstChild(fish.name) then
			local FishVal = Instance.new("StringValue")
			FishVal.Name = fish.name
			FishVal.Value = fish.name

			for _, attribute in pairs(fish.attributes) do
				local attrVal = Instance.new("NumberValue")
				attrVal.Name = attribute.name
				attrVal.Value = attribute.val
				attrVal.Parent = FishVal
			end

			FishVal.Parent = Fishes
		end
	end
end
return FishMod
2 Likes

Lifesaver! Thank you so much. I also appreciate you explaining the problem instead of just putting the code unlike some other people on the forum. Marked as solution, thank you so much!

1 Like