Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

for i,v in pairs do only clone 1 time instead of 4 ????

I have a (Dictionary) like this (Basically this module is for the lucky box)

local Inventory = {
	["Starter"] = {
		["Cost"] = 200,
		["Sword"] = {
			["Ice"] = {"Ice", 35}, --35 is the rarity
			["Fire"] = {"Fire", 35},
			["Water"] = {"Water", 20},
			["Soil"] = {"Soil", 10},
		}
	}
	
	
}

return Inventory

and i want to make a Image GUI for the ice,fire,water, and soil but why this script only Clone 1 Image Template instead of 4???

local ShopData = require(script.ModuleScript)

template.MouseButton1Click:Connect(function()
	for i,v in pairs(ShopData["Starter"]["Sword"]) do
			local CloneTemp = script.Template:Clone()
			CloneTemp.Parent = script.Parent.ScrollingFrame
			CloneTemp.Name = v[1]
			CloneTemp.SwordName.Text = v[1]
			CloneTemp.Percent.Text = v[2] .."%"
			
		end
end)

EDIT: this script works fine guys, my mistakes i forgot that i add this after the for i,v instead of after click

for a,x in pairs (Detail.Info.List:GetChildren()) do --Clear the previous layout
			if x.Name ~= "UIGridLayout" then
				x:Destroy()
				x = nil
			end
		end

4 comments

0

Is the template supposed to be different for each one? I don't really understand what you need from this.

0

yess supposed to be different,  But the script only clone 1 time instead of 4. The script need to clone the template for the ice, water, fire, soil 

0

I have a lucky-block like crate that drops down. Its not very efficient, But it works. You will have to modify it to make it work in your game. (Because im so lazy duh) Just respond to this comment and i will give a answer containing the script. Just a suggestion.

0

My lucky block works fine, the problem is the display (a gui that contain the 'name' of that sword). That script only clone 1 times and not 4 times

1 answer

✓ Accepted answer

You made a dictionary, not a table, so you would need to use i as well.

local ShopData = require(script.ModuleScript)

template.MouseButton1Click:Connect(function()
    for i,v in pairs(ShopData["Starter"]["Sword"]) do
            local CloneTemp = script.Template:Clone()
            CloneTemp.Parent = script.Parent.ScrollingFrame
            CloneTemp.Name = i
            CloneTemp.PetName.Text = v[1]
            CloneTemp.Percent.Text = v[2]

        end
end)

I just changed the v to i.

1 comment

0

tried, but still only Clone 1 time (Name = Ice), instead of 4 times (Ice, Fire, Water, Soil), EDIT: my mistakes LOL

This discussion is preserved as it was. New answers, comments, and votes are closed.