Unable to clone TextButtons into ScrollingFrame via ModuleScript

  1. What do you want to achieve? Keep it simple and clear!
    -I’m trying to make a shop system. Nothing trying to do related to the actual shop now, since it’s out of my focus now. I’m just trying to make a scolling thing using a ModuleScript

  2. What is the issue? Include screenshots / videos if possible!
    -TextButtons aren’t appearing in a ScrollingFrame

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    -I’ve tried looking but nothing matched my problem.

When I run the game, nothing happens. No textbuttons are cloned into the scrollingframe.

LocalScript

   task.wait()
module = require(game.ReplicatedStorage.Shop)
if not module then error("Module not found!") end
task.wait()
for i = 1, #module.items do
	item = module.items[i]
	button = script.TextButton:Clone()
	button.Parent=script.Parent.ScrollingFrame
	button.Name=item.Name
end

ModuleScript (in replicatedstorage)

local module = {
	items = {
		Steelshrieker = {
			Price = 0,
			Name = "Steelshrieker",
			Desc = "A typical sword. Recommended all-around for newbie players.",
			Item = game.ReplicatedStorage.Items.Steelshrieker
		},
		Silvershank = {
			Price = 25,
			Name = "Silvershank",
			Desc = "Lightweight dagger. It has spikes on the tip that, when pulled out, makes the enemy want to die, as if they weren't already dead. Good for people who like to spam.",
			Item = game.ReplicatedStorage.Items.Silvershank
		},
		Stonebear = {
			Price = 100,
			Name = "Stonebear",
			Desc = "Very heavy stone axe. Hits like a truck but definitely doesn't have the speed of one.",
			Item = game.ReplicatedStorage.Items.Stonebear
		},
		ClassicSword = {
			Price = 250,
			Name = "ClassicSword",
			Desc = "A linked sword with damage heavily nerfed and for good reason. Recommended if you're good at SFOTH.",
			Item = game.ReplicatedStorage.Items["Classic Sword"]
		},
		Skullcracker = {
			Price = 300,
			Name = "Skullcracker",
			Desc = "Slightly heavy mace with spikes. Good if you want decent damage without sacrificing much speed.",
			Item = game.ReplicatedStorage.Items.Steelshrieker --will implement mace later
		},
	}
}

return module


This syntax for getting the number of items only works for arrays, not dictionaries (like you have in your code).

I would recommend changing the loop to be like this:

for key, item in module.items do
	button = script.TextButton:Clone()
	button.Parent=script.Parent.ScrollingFrame
	button.Name=item.Name
end

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