Server script service scripts:
local Remote = game.ReplicatedStorage.CaseRemotes.BuyCase
Remote.OnServerEvent:Connect(function(Player)
Player.leaderstats.Money.Value -= 100
end)
game.Players.PlayerAdded:Connect(function(p)
local stats = Instance.new(“IntValue”)
stats.Name = “leaderstats”
stats.Parent = p
local money = Instance.new("IntValue", stats)
money.Name = "Money"
money.Value = 500
end)
scripts in my Case opening gui: local Tools = game.ServerStorage.Tools
game.ReplicatedStorage.CaseRemotes.GetItem.OnServerEvent:Connect(function(plr, item, rarity)
local UnboxedTool = Tools:FindFirstChild(item)
if UnboxedTool then
local Clone = UnboxedTool:Clone()
Clone.Parent = plr.Backpack
end
end)
local Player = game.Players.LocalPlayer
local cooldown = 1
debounce = false
local Tool = {
{Name = “ClassicSword”, Rarity = “Common”},
{Name = “Key”, Rarity = “Basic”},
{Name = “Robux”, Rarity = “Rare”},
{Name = “WaterBottle”, Rarity = “Legendary”},
}
local ToolTable = {
{tool = Tool[1], Weight = 100},
{tool = Tool[2], Weight = 60},
{tool = Tool[3], Weight = 30},
{tool = Tool[4], Weight = 15},
}
local color = {
{Rarity = “Common”, Color = Color3.fromRGB(118,118,118)},
{Rarity = “Basic”, Color = Color3.fromRGB(203, 222, 241)},
{Rarity = “Rare”, Color = Color3.fromRGB(32, 214, 255)},
{Rarity = “Legendary”, Color = Color3.fromRGB(240, 23, 255)},
}
local function returnWeight(ToolTable)
local s = 0
for i, entry in pairs(ToolTable) do
s = s + entry.Weight
end
return s
end
local function getRandomItem(ToolTable)
local randomNumber = math.random(returnWeight(ToolTable))
for i, entry in ipairs(ToolTable) do
if randomNumber <= entry.Weight then
return entry.tool
else
randomNumber = randomNumber - entry.Weight
end
end
end
script.Parent.TextButton.MouseButton1Click:Connect(function()
if Player.leaderstats.Money.Value >= 100 then
game.ReplicatedStorage.CaseRemotes.BuyCase:FireServer(Player)
if debounce == false then
script.Parent.UnboxFrame.Rarity.TextColor3 = Color3.new(1,1,1)
script.Parent.UnboxFrame.ItemName.Text = “None”
debounce = true
for count = 1,35 do
local item = getRandomItem(ToolTable)
local rarity = item.Rarity
script.Parent.UnboxFrame.ItemName.Text = item.Name
script.Parent.UnboxFrame.Rarity.Text = item.Rarity
for i, v in ipairs(color) do
if v.Rarity == rarity then
script.Parent.UnboxFrame.Rarity.TextColor3 = v.Color
end
end
wait(0.025)
end
local item = getRandomItem(ToolTable)
local name = item.Name
local rarity = item.Rarity
script.Parent.UnboxFrame.Rarity.Text = rarity
script.Parent.UnboxFrame.ItemName.Text = name
game.ReplicatedStorage.CaseRemotes.GetItem:FireServer(name, rarity)
for i, v in ipairs(color) do
if v.Rarity == rarity then
script.Parent.UnboxFrame.Rarity.TextColor3 = v.Color
end
end
wait(cooldown)
debounce = false
end
else
script.Parent.TextButton.Text = "Not enough Money!"
wait(1)
script.Parent.TextButton.Text = "Buy Case [100$]"
end
end)