PlayerAdded not running?

Hello Developers,

I have a script in my game that takes all of the seeds that are in the game (From a table in a module script) and makes GUIs for them in the shop when a player joins, but for some reason the GUIs aren’t added.

Script (server):

local players = game.Players
local cropHandler = require(game.ServerScriptService.CropHandler)


--Setup shop
players.PlayerAdded:Connect(function(player)
	task.wait(1)
	for i = 1, #cropHandler.CropInfo, 1 do
		local templateClone = game.ReplicatedStorage.SeedGuiTemplate:Clone()
		templateClone.Name = cropHandler.CropInfo[i]
		print(cropHandler.CropInfo[i])
		templateClone.Parent = player.PlayerGui.SeedsGui.Shop.Frame.Main.SeedDisplay
		templateClone.Main.SeedsImage.SeedName.Text = cropHandler.CropInfo[i]
		templateClone.Main.SeedsImage.SeedPrice.Text = "$"..tostring(cropHandler.CropInfo[i].Cost)
	end
end)

Here is the CropHandler (module):

local CropHandler = {}

CropHandler.CropInfo = {
	["Wheat"] = {
		ExpGiven = 1,
		CoinsGiven = 1,
		GrowingTime = 15,
		Cost = 0,
		Image = ""
	},
	
	["Carrot"] = {
		ExpGiven = 2,
		CoinsGiven = 3,
		GrowingTime = 25,
		Cost = 20,
		Image = ""
	},
	
	["Tomato"] = {
		ExpGiven = 3,
		CoinsGiven = 6,
		GrowingTime = 35,
		Cost = 40,
		Image = ""
	},
	
	["Beet"] = {
		ExpGiven = 2,
		CoinsGiven = 2,
		GrowingTime = 25,
		Cost = 40,
		Image = ""
	},
	
	["Pumpkin"] = {
		ExpGiven = 4,
		CoinsGiven = 10,
		GrowingTime = 40,
		Cost = 70,
		Image = ""
	},
	
	["Pepper"] = {
		ExpGiven = 3,
		CoinsGiven = 6,
		GrowingTime = 30,
		Cost = 70,
		Image = ""
	},
	
	["Corn"] = {
		ExpGiven = 5,
		CoinsGiven = 15,
		GrowingTime = 60,
		Cost = 100,
		Image = ""
	},
	
	["Evergreen"] = {
		ExpGiven = 7,
		CoinsGiven = 20,
		GrowingTime = 120,
		Cost = 160,
		Image = ""
	}
}

return CropHandler


Here are what the GUI objects look like in the Explorer:
Screen Shot 2023-09-30 at 9.43.01 AM

Screen Shot 2023-09-30 at 9.43.33 AM

There aren’t any output errors.

Please help!

cropHandler.cropinfo is a dictionary made of keys (e.g “wheat”) and values, but you are attempting to access them using an index number in the loop.
Also, the # tends to not count the number of keys.
It would be better to use

for key, value in pairs(cropHandler.cropinfo) do
--clone and stuff
end

I think it’s because if you have dictionary you cannot do #cropHandler.CropInfo, but rather a specific number. Try printing the #cropHandler.CropInfo.

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