Client
.MouseButton1Click:Connect(function()
Local SelectedCase = ui:GetAttribute("SelectedCase")
local ItemWon = RF:InvokeServer("OpenCase", SelectedCase)
print("Won item; " .. ItemWon
end)
Server
local CaseData = {"Item 1", "Item 2", "Item 3"} -- Casedata should be a module script. If you want to randomize order every time you need to make a server side function to do so
local IsSpinning = {} -- UserID: SpinTick
local TimePerItem = 0.5
local function SpinCase(Player:Player, CaseData)
local TotalItems = #CaseData
if not IsSpinning[Player.UserId] then
print("IsSpinning")
IsSpinning[Player.UserId] = tick()
else
local SpinTime = IsSpinning[Player.UserId]
local SpinDuration = tick() - SpinTime
local CycleTime = TotalItems * TimePerItem
local TotalTime = SpinDuration % CycleTime
local IndexItem = math.round(TotalTime / TimePerItem) % TotalItems + 1
print("StoppedSpinning. Indexed Time; " .. TotalTime .. " Won Item; " .. CaseData[IndexItem] )
IsSpinning[Player.UserId] = nil
end)
RF.OnServerInvoke = function(Player, Event, Data) -- Data should be string for this event
if Event == "OpenCase" and Data then
-- Check if enough coins or whatever
SpinCase(Player, Data)
end
end