-- Generated Roblox candy game asset preview grid. Does not publish or upload anything.
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Selection = game:GetService("Selection")
local function color(rgb) return Color3.fromRGB(rgb[1], rgb[2], rgb[3]) end
local items = {
  {index=1,itemId="candy_001_wrapped_starburst_hard_candy",name="Wrapped Starburst Hard Candy",candyType="wrapped hard candy",rarity="common",value=5,consumable=true,color={255,74,112},accent={255,210,72}},
  {index=2,itemId="candy_002_chunky_choco_tile",name="Chunky Choco Tile",candyType="chocolate bar",rarity="common",value=5,consumable=true,color={87,43,28},accent={138,71,43}},
  {index=3,itemId="candy_003_rainbow_lolly_loop",name="Rainbow Lolly Loop",candyType="lollipop",rarity="uncommon",value=12,consumable=true,color={255,72,72},accent={255,198,59}},
  {index=4,itemId="candy_004_squishy_gummy_bear",name="Squishy Gummy Bear",candyType="gummy bear",rarity="uncommon",value=12,consumable=true,color={55,210,145},accent={110,255,190}},
  {index=5,itemId="candy_005_winter_candy_cane",name="Winter Candy Cane",candyType="candy cane",rarity="common",value=5,consumable=true,color={245,245,245},accent={220,32,52}},
  {index=6,itemId="candy_006_cosmic_jawbreaker",name="Cosmic Jawbreaker",candyType="jawbreaker",rarity="rare",value=25,consumable=true,color={80,95,255},accent={255,105,180}},
  {index=7,itemId="candy_007_sour_neon_strip",name="Sour Neon Strip",candyType="sour strip",rarity="uncommon",value=12,consumable=true,color={55,235,230},accent={255,68,170}},
  {index=8,itemId="candy_008_speckled_jelly_bean",name="Speckled Jelly Bean",candyType="jelly bean",rarity="common",value=5,consumable=true,color={255,132,58},accent={255,214,112}},
  {index=9,itemId="candy_009_gold_wrap_caramel_cube",name="Gold-Wrap Caramel Cube",candyType="caramel cube",rarity="uncommon",value=12,consumable=true,color={184,111,51},accent={255,205,81}},
  {index=10,itemId="candy_010_twisted_licorice_rope",name="Twisted Licorice Rope",candyType="licorice twist",rarity="common",value=5,consumable=true,color={178,18,42},accent={235,72,98}},
  {index=11,itemId="candy_011_marshmallow_sky_swirl",name="Marshmallow Sky Swirl",candyType="marshmallow swirl",rarity="uncommon",value=12,consumable=true,color={255,245,248},accent={160,220,255}},
  {index=12,itemId="candy_012_cloud_cotton_puff",name="Cloud Cotton Puff",candyType="cotton candy puff",rarity="rare",value=25,consumable=true,color={255,149,214},accent={142,216,255}},
  {index=13,itemId="candy_013_peppermint_shield_disk",name="Peppermint Shield Disk",candyType="peppermint disk",rarity="common",value=5,consumable=true,color={255,255,255},accent={221,35,58}},
  {index=14,itemId="candy_014_rock_candy_crystal",name="Rock Candy Crystal",candyType="rock candy crystal",rarity="rare",value=25,consumable=false,color={63,202,255},accent={135,238,255}},
  {index=15,itemId="candy_015_bubblegum_planet_ball",name="Bubblegum Planet Ball",candyType="bubblegum ball",rarity="rare",value=25,consumable=true,color={255,104,190},accent={118,218,255}},
  {index=16,itemId="candy_016_tri_color_candy_corn",name="Tri-Color Candy Corn",candyType="candy corn",rarity="common",value=5,consumable=true,color={255,248,222},accent={255,182,55}},
  {index=17,itemId="candy_017_cocoa_star_truffle",name="Cocoa Star Truffle",candyType="chocolate truffle",rarity="uncommon",value=12,consumable=true,color={92,48,35},accent={245,210,155}},
  {index=18,itemId="candy_018_frosted_cookie_candy",name="Frosted Cookie Candy",candyType="frosted cookie candy",rarity="uncommon",value=12,consumable=true,color={202,142,79},accent={255,240,255}},
  {index=19,itemId="candy_019_squiggle_gummy_worm",name="Squiggle Gummy Worm",candyType="gummy worm",rarity="common",value=5,consumable=true,color={64,224,126},accent={255,92,152}},
  {index=20,itemId="candy_020_pulled_taffy_pillow",name="Pulled Taffy Pillow",candyType="taffy piece",rarity="common",value=5,consumable=true,color={255,188,220},accent={255,245,250}},
  {index=21,itemId="candy_021_wrapped_fruit_chew",name="Wrapped Fruit Chew",candyType="fruit chew",rarity="common",value=5,consumable=true,color={255,135,42},accent={35,198,92}},
  {index=22,itemId="candy_022_sprinkle_crunch_cluster",name="Sprinkle Crunch Cluster",candyType="sprinkle cluster",rarity="uncommon",value=12,consumable=true,color={115,62,40},accent={255,78,113}},
  {index=23,itemId="candy_023_candy_button_sheet",name="Candy Button Sheet",candyType="candy button sheet",rarity="common",value=5,consumable=false,color={250,250,236},accent={255,87,128}},
  {index=24,itemId="candy_024_choco_coin_medal",name="Choco Coin Medal",candyType="chocolate coin",rarity="rare",value=25,consumable=false,color={255,202,65},accent={255,240,160}},
  {index=25,itemId="candy_025_mystery_glow_candy",name="Mystery Glow Candy",candyType="mystery glowing candy",rarity="legendary",value=100,consumable=true,color={115,82,255},accent={33,255,210}},
}

local function resetFolder(parent, name)
    local old = parent:FindFirstChild(name)
    if old then old:Destroy() end
    local folder = Instance.new("Folder")
    folder.Name = name
    folder.Parent = parent
    return folder
end

local previewRoot = resetFolder(Workspace, "CandyAssetPreviewGrid")
local readyRoot = ReplicatedStorage:FindFirstChild("RobloxReadyGameAssets") or Instance.new("Folder")
readyRoot.Name = "RobloxReadyGameAssets"
readyRoot.Parent = ReplicatedStorage
local readyCandy = resetFolder(readyRoot, "Candy")

local function addPart(model, name, shape, size, cf, rgb, material)
    local p = Instance.new("Part")
    p.Name = name
    p.Anchored = true
    p.CanCollide = true
    p.CanTouch = true
    p.CanQuery = true
    p.Size = size
    p.CFrame = cf
    p.Color = color(rgb)
    p.Material = material or Enum.Material.SmoothPlastic
    if shape then p.Shape = shape end
    p.TopSurface = Enum.SurfaceType.Smooth
    p.BottomSurface = Enum.SurfaceType.Smooth
    p.Parent = model
    return p
end

local function addLabel(model, text, cf)
    local anchor = addPart(model, "LabelAnchor", nil, Vector3.new(0.2,0.2,0.2), cf + Vector3.new(0,3.1,0), {255,255,255}, Enum.Material.SmoothPlastic)
    anchor.Transparency = 1
    anchor.CanCollide = false
    local gui = Instance.new("BillboardGui")
    gui.Name = "CandyLabel"
    gui.Size = UDim2.fromOffset(220, 54)
    gui.StudsOffset = Vector3.new(0, 1.2, 0)
    gui.AlwaysOnTop = true
    gui.Parent = anchor
    local label = Instance.new("TextLabel")
    label.BackgroundTransparency = 0.2
    label.BackgroundColor3 = Color3.fromRGB(255,255,255)
    label.TextColor3 = Color3.fromRGB(32,36,42)
    label.TextScaled = true
    label.Font = Enum.Font.GothamBold
    label.Text = text
    label.Size = UDim2.fromScale(1,1)
    label.Parent = gui
end

local function addAttributes(model, item)
    model:SetAttribute("CandyName", item.name)
    model:SetAttribute("CandyType", item.candyType)
    model:SetAttribute("Rarity", item.rarity)
    model:SetAttribute("IsCollectible", true)
    model:SetAttribute("PickupValue", item.value)
    model:SetAttribute("IsConsumable", item.consumable)
    model:SetAttribute("ItemId", item.itemId)
    model:SetAttribute("Category", "game_asset_candy")
    model:SetAttribute("RobloxImportStatus", "preview_model_created_pending_fbx_meshpart_import")
    model:SetAttribute("NotAvatarAccessory", true)
end

local function buildCandy(model, item, base)
    local i = item.index
    local c = item.color
    local a = item.accent
    if i == 2 then
        addPart(model,"ChocolateBase",nil,Vector3.new(3.8,.45,2.1),base,c,Enum.Material.SmoothPlastic)
        for x=-1,1 do for z=-1,1,2 do addPart(model,"Pip",nil,Vector3.new(.75,.32,.55),base*CFrame.new(x*1.05,.38,z*.45),a,Enum.Material.SmoothPlastic) end end
    elseif i == 3 or i == 6 or i == 15 or i == 24 then
        addPart(model,"RoundCandy",Enum.PartType.Ball,Vector3.new(2.6,2.6,2.6),base,c,Enum.Material.SmoothPlastic)
        addPart(model,"CandyRing",Enum.PartType.Cylinder,Vector3.new(.25,3.2,3.2),base*CFrame.Angles(0,0,math.rad(90)),a,Enum.Material.Neon)
        if i == 3 then addPart(model,"Stick",nil,Vector3.new(.22,2.6,.22),base*CFrame.new(0,-2.1,0),{245,245,245},Enum.Material.SmoothPlastic) end
    elseif i == 4 then
        addPart(model,"Body",Enum.PartType.Ball,Vector3.new(1.9,2.4,1.4),base,c,Enum.Material.SmoothPlastic)
        addPart(model,"Head",Enum.PartType.Ball,Vector3.new(1.5,1.3,1.25),base*CFrame.new(0,1.55,0),c,Enum.Material.SmoothPlastic)
        for _,x in ipairs({-.65,.65}) do addPart(model,"Ear",Enum.PartType.Ball,Vector3.new(.6,.6,.6),base*CFrame.new(x,2.25,0),a,Enum.Material.SmoothPlastic) end
    elseif i == 5 then
        for n=1,8 do addPart(model,"CaneSegment",nil,Vector3.new(.45,.45,.95),base*CFrame.new(math.sin(n*.35)*.65,-1.8+n*.42,0)*CFrame.Angles(0,0,math.rad(n*10)),(n%2==0) and a or c,Enum.Material.SmoothPlastic) end
    elseif i == 7 or i == 10 or i == 19 then
        for n=1,9 do addPart(model,"CandySegment",Enum.PartType.Ball,Vector3.new(.65,.5,.5),base*CFrame.new(-2.0+n*.45,math.sin(n*.8)*.35,0),(n%2==0) and a or c,Enum.Material.SmoothPlastic) end
    elseif i == 11 or i == 14 or i == 25 then
        for n=1,7 do addPart(model,"StackShard",nil,Vector3.new(.65,.28,.65),base*CFrame.new(0,-1.4+n*.42,0)*CFrame.Angles(0,math.rad(n*22),0),(n%2==0) and a or c,(i==25) and Enum.Material.Neon or Enum.Material.SmoothPlastic) end
    elseif i == 12 then
        for n=1,6 do addPart(model,"CloudLobe",Enum.PartType.Ball,Vector3.new(1.2,1.0,1.0),base*CFrame.new(math.cos(n)*.9,math.sin(n*1.7)*.45+.7,math.sin(n)*.45),(n%2==0) and a or c,Enum.Material.SmoothPlastic) end
        addPart(model,"Cone",Enum.PartType.Cylinder,Vector3.new(.45,1.6,.45),base*CFrame.new(0,-1.35,0),{242,220,178},Enum.Material.SmoothPlastic)
    elseif i == 16 then
        addPart(model,"CandyCornBase",nil,Vector3.new(2.5,.65,1.8),base*CFrame.new(0,-.7,0),{255,104,39},Enum.Material.SmoothPlastic)
        addPart(model,"CandyCornMid",nil,Vector3.new(1.75,.65,1.35),base*CFrame.new(0,0,0),{255,182,55},Enum.Material.SmoothPlastic)
        addPart(model,"CandyCornTip",nil,Vector3.new(.9,.65,.8),base*CFrame.new(0,.72,0),{255,248,222},Enum.Material.SmoothPlastic)
    elseif i == 18 or i == 22 or i == 23 then
        addPart(model,"FlatBase",nil,Vector3.new(3.2,.25,2.2),base,c,Enum.Material.SmoothPlastic)
        for n=1,12 do addPart(model,"Sprinkle",nil,Vector3.new(.28,.12,.12),base*CFrame.new(math.cos(n)*1.1,.28,math.sin(n*2.1)*.75)*CFrame.Angles(0,math.rad(n*20),0),(n%2==0) and a or {255,255,255},Enum.Material.SmoothPlastic) end
    else
        addPart(model,"MainCandy",nil,Vector3.new(3.1,1.25,1.8),base,c,Enum.Material.SmoothPlastic)
        addPart(model,"AccentLeft",nil,Vector3.new(.75,.8,1.5),base*CFrame.new(-2.05,0,0),a,Enum.Material.SmoothPlastic)
        addPart(model,"AccentRight",nil,Vector3.new(.75,.8,1.5),base*CFrame.new(2.05,0,0),a,Enum.Material.SmoothPlastic)
    end
end

for _, item in ipairs(items) do
    local model = Instance.new("Model")
    model.Name = string.format("%02d_%s", item.index, item.itemId)
    addAttributes(model, item)
    local col = (item.index - 1) % 5
    local row = math.floor((item.index - 1) / 5)
    local base = CFrame.new((col - 2) * 7, 4, 82 + row * 7)
    buildCandy(model, item, base)
    addLabel(model, string.format("%02d %s", item.index, item.name), base)
    local firstPart = model:FindFirstChildWhichIsA("BasePart")
    if firstPart then model.PrimaryPart = firstPart end
    model.Parent = previewRoot
    local ready = model:Clone()
    ready.Name = model.Name
    ready.Parent = readyCandy
end

local accessoryCount = 0
for _, inst in ipairs(previewRoot:GetDescendants()) do
    if inst:IsA("Accessory") then accessoryCount += 1 end
end
Selection:Set({previewRoot})
return string.format("candy preview grid install ok; workspace=%d; ready=%d; accessories=%d", #previewRoot:GetChildren(), #readyCandy:GetChildren(), accessoryCount)
