Below is a COMPLETE, drop-in “starter kit” for a Roblox crate-opening system that is split cleanly between server and client:
• The server
– validates the request
– picks the loot with weighting
– sends the result to the client only after it has been locked-in (cheat-proof).
• The client
– plays the scrolling/slow-down animation in a GUI
– stops exactly on the reward the server already chose.
Feel free to rename folders or asset IDs to match your own project, but if you copy the hierarchy and the scripts 1-for-1, it will work out of the box.
- GAME EXPLORER HIERARCHY
ReplicatedStorage
└─ RemoteEvents
├─ OpenCrateRequest (RemoteEvent)
└─ RollOutcome (RemoteEvent)
ServerScriptService
└─ CrateServer (Script ‑ see §2)
StarterGui
└─ CrateGui (ScreenGui)
├─ OpenButton (TextButton)
└─ ReelFrame (Frame) – holds the ScrollingFrame
└─ Reel (ScrollingFrame)
– “TemplateItem” (Frame) – a single reward tile, used as template
(Contains ImageLabel + TextLabel)
StarterPlayer
└─ StarterPlayerScripts
└─ CrateClient (LocalScript ‑ see §3)
- SERVER: CrateServer (Script)
-- ServerScriptService/CrateServer
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local OPEN_EVENT = RS.RemoteEvents.OpenCrateRequest
local OUTCOME_EVENT = RS.RemoteEvents.RollOutcome
--------------------------------------------------------------------
-- CONFIGURATION
--------------------------------------------------------------------
local LootPool = {
-- {Name, AssetId, Weight, RarityColor}
{"Common Sword", "rbxassetid://12345678", 50, Color3.fromRGB(180,180,180)},
{"Cool Hat", "rbxassetid://87654321", 30, Color3.fromRGB(120,200,255)},
{"Epic Blaster", "rbxassetid://44556677", 15, Color3.fromRGB(255, 80,255)},
{"Legendary Aura", "rbxassetid://99887766", 5, Color3.fromRGB(255,215, 0)},
}
--------------------------------------------------------------------
-- UTILITY: Weighted random pick
--------------------------------------------------------------------
local function chooseWeighted(pool)
local total = 0
for _, item in ipairs(pool) do
total += item[3]
end
local threshold = math.random() * total
local cumulative = 0
for index, item in ipairs(pool) do
cumulative += item[3]
if threshold <= cumulative then
return index -- return the *index* so the client can also rebuild the visual list
end
end
return #pool -- fallback
end
--------------------------------------------------------------------
-- MAIN EVENT HANDLERS
--------------------------------------------------------------------
OPEN_EVENT.OnServerEvent:Connect(function(player)
----------------------------------------------------------------
-- 1) VALIDATION (Does the player actually have a crate?)
----------------------------------------------------------------
-- NOTE: Replace this block with your real inventory logic
local hasCrate = true
if not hasCrate then
return
end
----------------------------------------------------------------
-- 2) CONSUME CRATE + ROLL
----------------------------------------------------------------
local chosenIndex = chooseWeighted(LootPool)
local rewardData = LootPool[chosenIndex]
-- If using a real inventory, give the item here!
-- e.g. InventoryService:Give(player, rewardData[1])
----------------------------------------------------------------
-- 3) SEND RESULT TO CLIENT
----------------------------------------------------------------
OUTCOME_EVENT:FireClient(player, {
Pool = LootPool, -- client rebuilds the reel UI from this
WinningSlot = chosenIndex
})
end)
- CLIENT: CrateClient (LocalScript)
-- StarterPlayerScripts/CrateClient
local RS = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui"):WaitForChild("CrateGui")
local OPEN_EVENT = RS.RemoteEvents.OpenCrateRequest
local OUTCOME_EVENT = RS.RemoteEvents.RollOutcome
-- UI references
local openBtn = gui.OpenButton
local reelFrame = gui.ReelFrame
local reelScroll = reelFrame.Reel
local template = reelScroll.TemplateItem
-- animation constants
local LOOP_COUNT = 3 -- how many extra spins before slowing down
local ITEM_PADDING = 10 -- px between items
local SLOW_STEPS = 25 -- tween steps for slowdown
local MAX_SPEED = 0.1 -- seconds per item at max speed
local FINAL_SPEED = 0.6 -- seconds per item at the very end
--------------------------------------------------------------------
-- BUILD THE REEL VISUALLY
--------------------------------------------------------------------
local function buildReel(pool)
reelScroll:ClearAllChildren()
local totalWidth = 0
for i, item in ipairs(pool) do
local clone = template:Clone()
clone.Name = "Item_"..i
clone.ItemName.Text = item[1]
clone.ItemImage.Image= item[2]
clone.ItemName.TextColor3 = item[4]
clone.Visible = true
clone.Parent = reelScroll
-- layout manually
clone.Position = UDim2.new(0, totalWidth, 0, 0)
totalWidth += clone.Size.X.Offset + ITEM_PADDING
end
-- Duplicate the list once so we can loop seamlessly
for i, item in ipairs(pool) do
local clone = template:Clone()
clone.Name = "Loop_"..i
clone.ItemName.Text = item[1]
clone.ItemImage.Image= item[2]
clone.ItemName.TextColor3 = item[4]
clone.Visible = true
clone.Parent = reelScroll
clone.Position = UDim2.new(0, totalWidth, 0, 0)
totalWidth += clone.Size.X.Offset + ITEM_PADDING
end
reelScroll.CanvasSize = UDim2.new(0, totalWidth, 0, reelScroll.AbsoluteSize.Y)
end
--------------------------------------------------------------------
-- PLAY THE ANIMATION
--------------------------------------------------------------------
local rolling = false
local function playRoll(data)
rolling = true
openBtn.Visible = false
local pool = data.Pool
local winSlot = data.WinningSlot
buildReel(pool)
reelScroll.CanvasPosition = Vector2.new(0,0)
-- Calculate where we need to stop (the start pixel of winning index)
local itemWidth = template.Size.X.Offset + ITEM_PADDING
local winningX = (winSlot-1) * itemWidth -- 0-based offset
-- total distance = (POOL_LEN * LOOP_COUNT + winSlot) items
local spins = (#pool * LOOP_COUNT + winSlot-1) * itemWidth
local currentPos = 0
local speed = MAX_SPEED
for i = 1, #pool * LOOP_COUNT + winSlot + SLOW_STEPS do
-- gradually interpolate speed
local alpha = math.clamp(i - ((#pool * LOOP_COUNT + winSlot)), 0, SLOW_STEPS)/SLOW_STEPS
local thisSpeed = MAX_SPEED + (FINAL_SPEED - MAX_SPEED) * alpha
currentPos += itemWidth
local tween = TweenService:Create(reelScroll, TweenInfo.new(thisSpeed, Enum.EasingStyle.Linear),
{CanvasPosition = Vector2.new(currentPos, 0)})
tween:Play()
tween.Completed:Wait()
end
-- snap exactly to winning position (visual error-proof)
reelScroll.CanvasPosition = Vector2.new(winningX, 0)
-- flash / celebrate
local winItem = reelScroll:FindFirstChild("Item_"..winSlot)
if winItem then
local flash = TweenService:Create(winItem, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut,5,true),
{BackgroundTransparency = 0.2})
flash:Play()
end
rolling = false
task.wait(1)
openBtn.Visible = true
end
--------------------------------------------------------------------
-- GUI TRIGGERS
--------------------------------------------------------------------
openBtn.MouseButton1Click:Connect(function()
if rolling then return end
OPEN_EVENT:FireServer() -- send request to server
end)
OUTCOME_EVENT.OnClientEvent:Connect(playRoll)
- GUI TEMPLATE QUICK NOTES
TemplateItem (Frame)
• Size : {0, 120},{0, 120} (change as you like)
• BackgroundTransparency : 0.5
└─ ItemImage (ImageLabel) – fills most of the frame
└─ ItemName (TextLabel) – anchored at bottom, background transparency = 1
Make sure TemplateItem.Visible is false in Studio so only the script clones it.
- WHAT TO EDIT / EXPAND
• Swap in your own asset IDs & rarity colors.
• Hook inventory checks / crate removal into the validation section on the server.
• Award the item to the player in the same server script (after “-- give item here”).
• Adjust animation constants (LOOP_COUNT, SLOW_STEPS, speeds) for different pacing.
• Add sound effects: play a “tick” each step, a whoosh while fast, and a “bam!” at the end.
Have fun & happy crate-opening! 🎁