Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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
0
Is the template supposed to be different for each one? I don't really understand what you need from this. waifuSZN 123 — 4y
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  revolusi 48 — 4y
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. hasanchik 49 — 4y
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 revolusi 48 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

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

Answer this question