#trying to make a spin system (similar to spin a baddie)

1 messages · Page 1 of 1 (latest)

slim yacht
#

basically my logic is that I have 40 empty boxes (frame) that is under a holder (frame) and also a uilistlayout with the boxes. then i press my spin button which spins and always lands on the 32th box. So I did that, then im trying to make the boxes pick from a folder that contains a Frame and under this frame is uicorner, uistroke, Imagelabel, Textlabel.

Each box will get frames from the folder so that they would have an icon. Im kinda new to scripting, so all ive been doing is scripting and asking chatgpt for help learning alongside it.

#

1st video is with the script that tries to make the box get the frames from the folder

#

2nd video is the script disabled

#

why is it that the first video, only the first box gets the frame

#

Under boxesframe on the very bottom is the boxes, its very long so it wont fit in a screenshot

slim yacht
#
local weaponsFolder = ReplicatedStorage:WaitForChild("Weapons")

local spinnerGUI = script.Parent
local spinBorder = spinnerGUI:WaitForChild("SpinBorder")
local holder = spinBorder:WaitForChild("Holder")

-- Get all boxes (ignore UIListLayout)
local boxFrames = {}
for _, child in ipairs(holder:GetChildren()) do
    if child:IsA("Frame") then
        table.insert(boxFrames, child)
    end
end

-- sort boxes by number name (01 → 40)
table.sort(boxFrames, function(a, b)
    return tonumber(a.Name) < tonumber(b.Name)
end)

local function assignWeapons()
    local weaponFrames = weaponsFolder:GetChildren()

    for i, box in ipairs(boxFrames) do
        -- clear old weapon frames
        for _, child in ipairs(box:GetChildren()) do
            child:Destroy()
        end

        local weaponClone
        if i == 32 then
            local winning = weaponsFolder:FindFirstChild("YourSpecialWeapon")
            weaponClone = winning and winning:Clone() or weaponFrames[1]:Clone()
        else
            weaponClone = weaponFrames[math.random(1,#weaponFrames)]:Clone()
        end

        -- Parent to box and fill it
        weaponClone.Parent = box
        weaponClone.Size = UDim2.new(1,0,1,0)
        weaponClone.Position = UDim2.new(0,0,0,0)
        weaponClone.AnchorPoint = Vector2.new(0,0)
    end
end

-- populate boxes immediately
assignWeapons()```
#

and this is my box script that tries to make the boxes get frames from the folder

stray gulch
#

We might need to see the spin script. Also you are not showing the entire setup of your GUI, We don't see what is inside BoxesFrame. For me to help trouble shoot this would be helpful to see.

stray gulch
#

The weapons folder in Replicated Storage, is that just images of the weapons ?

stray gulch
#

this worked

#

ooh and i set it up with one 2 instead of the 40 you have in your script