I made a crate system, but there’s one issue. 90% of the images/frames dont load at all, and are just the placeholder. I assume its due to poor optimization. Help?
plr = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
if plr.leaderstats.CommonCrates.Value > 0 then
plr.leaderstats.CommonCrates.Value -= 1
plr.PlayerGui.CommonCrate.Frame.Visible = true
script.Parent.Parent.Parent.Parent.Parent.Parent.Enabled = false
local win = nil
for i = 1, 25 do
local random1 = math.random(1,100)
local clo = game.ServerStorage.Template:Clone()
clo.Parent = plr.PlayerGui.CommonCrate.Frame.Frame.hd
if NumberRange.new(1,70).Min < random1 and random1 < NumberRange.new(1,70).Max or NumberRange.new(1,70).Min == random1 or NumberRange.new(1,70).Max == random1 then
local random = math.random(1,7)
for i, v in pairs(game.ServerStorage.Skins.Common:GetChildren()) do
if v:GetAttribute("rank") == random then
local clo2 = v:Clone()
clo2.Parent = clo.ViewportFrame.WorldModel
clo2.Handle.Position = Vector3.new(0,0,0)
clo.Name = clo2.Name
clo.BackgroundColor3 = Color3.new(0.75,0.75,0.75)
clo.TextLabel.Text = "COMMON"
clo.TextLabel.BackgroundColor3 = Color3.new(0.6,0.6,0.6)
end
end
end
if NumberRange.new(70,95).Min < random1 and random1 < NumberRange.new(70,95).Max or NumberRange.new(70,95).Min == random1 or NumberRange.new(70,95).Max == random1 then
local random = math.random(1,6)
for i, v in pairs(game.ServerStorage.Skins.Uncommon:GetChildren()) do
if v:GetAttribute("rank") == random then
local clo2 = v:Clone()
clo2.Parent = clo.ViewportFrame.WorldModel
clo2.Handle.Position = Vector3.new(0,0,0)
clo.Name = clo2.Name
clo.BackgroundColor3 = Color3.new(0,0.75,0)
clo.TextLabel.Text = "UNCOMMON"
clo.TextLabel.BackgroundColor3 = Color3.new(0,0.6,0)
end
end
end
if NumberRange.new(95,100).Min < random1 and random1 < NumberRange.new(95,100).Max or NumberRange.new(95,100).Min == random1 or NumberRange.new(95,100).Max == random1 then
local random = math.random(1,5)
for i, v in pairs(game.ServerStorage.Skins.Rare:GetChildren()) do
if v:GetAttribute("rank") == random then
local clo2 = v:Clone()
clo2.Parent = clo.ViewportFrame.WorldModel
clo2.Handle.Position = Vector3.new(0,0,0)
clo.Name = clo2.Name
clo.BackgroundColor3 = Color3.new(0.75,0,0)
clo.TextLabel.Text = "RARE"
clo.TextLabel.BackgroundColor3 = Color3.new(0.6,0,0)
end
end
end
if i == 19 then
win = clo
print("winna")
end
end
plr.PlayerGui.CommonCrate.Frame.Frame.hd:TweenPosition(UDim2.new(-4,0,0,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quart,8)
task.wait(9)
plr.PlayerGui.CommonCrate.Frame.Frame.hd.Position = UDim2.new(0,0,0,0)
local ski = Instance.new("Folder")
ski.Name = win.Name
ski.Parent = plr.Skins
plr.PlayerGui.CommonCrate.Frame.Visible = false
script.Parent.Parent.Parent.Parent.Parent.Parent.Enabled = true
for i, v in pairs(plr.PlayerGui.CommonCrate.Frame.Frame.hd:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
end
end)