crates client
crates client
local rs = game:GetService("ReplicatedStorage")
local remotes = rs:WaitForChild("RemoteEvents")
local rarityProperties = rs:WaitForChild("RarityProperties")
local items = rs:WaitForChild("Items")
local crates = rs:WaitForChild("Crates")
closeShopBtn.MouseButton1Click:Connect(function()
shopFrame.Visible = false
end)
closeOpenedBtn.MouseButton1Click:Connect(function()
openedFrame.Visible = false
openedGui.Enabled = false
newBtn.MouseButton1Click:Connect(function()
selectedCrate.CrateName.Text = crate.Name
selectedCrate.CrateImage.Image = crateProperties["Image"]
selectedCrate.UnboxButton.Text = "$" .. crateProperties["Price"]
local rarities = {}
for rarityName, chance in pairs(crateProperties["Chances"]) do
table.insert(rarities, {rarityName, chance})
end
table.sort(rarities, function(a, b)
return rarityProperties[a[1]].Order.Value
<rarityProperties[b[1]].Order.Value
end)
itemModel:PivotTo(CFrame.new() * CFrame.Angles(math.rad(-39), 0,
0))
itemModel.Parent = newItemFrame.ItemImage
newItemFrame.Parent = selectedCrate.ItemsList
end
selectedCrate.Visible = true
end
end)
table.sort(crateButtons, function(a, b)
return (a[2] < b[2]) or (a[2] == b[2] and a[1].Name < b[1].Name)
end)
--Purchasing crates
selectedCrate.UnboxButton.MouseButton1Click:Connect(function()
if selectedCrate.Visible == true and
game.Players.LocalPlayer.leaderstats.Cash.Value >=
tonumber(string.sub(selectedCrate.UnboxButton.Text, 2, -1)) then
remotes:WaitForChild("BuyCrate"):FireServer(selectedCrate.CrateName.Text)
end
end)
--Unboxing crates
function lerp(a, b, t)
return a + (b-a) * t
end
remotes:WaitForChild("CrateOpened").OnClientEvent:Connect(function(crateName,
itemChosen, unboxTime)
for i = 1, numItems do
if i ~= chosenPosition then
local rndChance = rnd:NextNumber() * 100
local n = 0
newItemFrame.Parent = openedItemsFrame.ItemsContainer
end
openedFrame.CrateName.Text = crateName
shopFrame.Visible = false
closeOpenedBtn.Visible = false
openedFrame.Visible = true
openedGui.Enabled = true
while true do
local timeSinceOpened = tick() - timeOpened
local x = timeSinceOpened / unboxTime
if x >= 1 then
break
end
game:GetService("RunService").Heartbeat:Wait()
end
closeOpenedBtn.Visible = true
end)