Advertisement
HowToRoblox

DailySpinClient

Sep 27th, 2022 (edited)
1,633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. local frame = script.Parent.SpinFrame
  2. frame.Visible = false
  3.  
  4. local btn = script.Parent.OpenSpinButton
  5.  
  6.  
  7. local lastSpunValue = game.Players.LocalPlayer:WaitForChild("LastSpun")
  8.  
  9. local re = game.ReplicatedStorage.DailySpinReplicatedStorage.DailySpinRE
  10.  
  11.  
  12. btn.MouseButton1Click:Connect(function()
  13.    
  14.     if not frame.Visible then
  15.        
  16.         local timeDiff = os.time() - lastSpunValue.Value
  17.        
  18.         if timeDiff >= 24 * 60 * 60 and frame.Visible == false then
  19.            
  20.             frame.CentrePivot:ClearAllChildren()
  21.             frame.CentrePivot.Rotation = Random.new():NextInteger(0, 360)
  22.            
  23.             frame.SpinButton.SpinText.Text = "SPIN!"
  24.            
  25.             local module = require(game.ReplicatedStorage.DailySpinReplicatedStorage.DailySpinSettings)
  26.             local rewards = module.rewards
  27.             local colours = module.colours
  28.            
  29.             local circumference = frame.CentrePivot.AbsoluteSize.X * math.pi
  30.             local numSectors = #rewards
  31.            
  32.             local absoluteSectorWidth = (circumference / numSectors)
  33.             local sectorWidth = absoluteSectorWidth / frame.CentrePivot.AbsoluteSize.X
  34.            
  35.             for i = #rewards, 2, -1 do
  36.                 local j = Random.new():NextInteger(1, i)
  37.                 rewards[i], rewards[j] = rewards[j], rewards[i]
  38.             end
  39.            
  40.             for i, reward in pairs(rewards) do
  41.                
  42.                 local newSector = script:WaitForChild("SectorPivot"):Clone()
  43.                 newSector.Name = i
  44.                
  45.                 newSector.Sector.Size = UDim2.new(sectorWidth, 0, 0.5, 0)
  46.  
  47.                 local rotation = (i - 1) * (360 / numSectors)
  48.                 newSector.Rotation = rotation
  49.                
  50.                 newSector.Sector.RewardAmount.Text = reward
  51.                
  52.                 newSector.Sector.ImageColor3 = colours[reward]
  53.                
  54.                 newSector.Parent = frame.CentrePivot
  55.             end
  56.            
  57.             frame.Visible = true
  58.         end
  59.        
  60.     else
  61.         frame.Visible = false
  62.     end
  63. end)
  64.  
  65. frame.SpinButton.MouseButton1Click:Connect(function()
  66.    
  67.     if frame.SpinButton.SpinText.Text == "SPIN!" then
  68.        
  69.         local timeDiff = os.time() - lastSpunValue.Value
  70.        
  71.         if timeDiff >= 24 * 60 * 60 then
  72.             re:FireServer()
  73.         end
  74.        
  75.     else
  76.         frame.Visible = false
  77.     end
  78. end)
  79.  
  80. re.OnClientEvent:Connect(function(rewardPos, spinTime)
  81.    
  82.     local rotAmount = Random.new():NextInteger(1, 4) * 360
  83.    
  84.     local ts = game:GetService("TweenService")
  85.     local tweenInfo = TweenInfo.new(spinTime, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
  86.    
  87.     local goalSector = frame.CentrePivot[rewardPos]
  88.     local sectorRot = goalSector.Rotation
  89.     rotAmount += (360 - sectorRot)
  90.    
  91.     local rotationTween = ts:Create(frame.CentrePivot, tweenInfo, {Rotation = rotAmount})
  92.     rotationTween:Play()
  93.    
  94.     rotationTween.Completed:Wait()
  95.    
  96.     frame.SpinButton.SpinText.Text = "CLAIM!"
  97. end)
  98.  
  99.  
  100. while task.wait(1) do
  101.    
  102.     local timeDiff = os.time() - lastSpunValue.Value
  103.     local timeLeft = (24 * 60 * 60) - timeDiff
  104.    
  105.     local h = math.floor(timeLeft / 60 / 60)
  106.     h = string.format("%0.2i", h)
  107.     local m = math.floor((timeLeft - (h * 60 * 60)) / 60)
  108.     m = string.format("%0.2i", m)
  109.     local s = timeLeft - (h * 60 * 60) - (m * 60)
  110.     s = string.format("%0.2i", s)
  111.    
  112.     btn.TimeToNextSpin.Text = h .. ":" .. m .. ":" .. s
  113.    
  114.     if timeDiff >= 24 * 60 * 60 then
  115.         btn.TimeToNextSpin.Visible = false
  116.         btn.ImageColor3 = Color3.fromRGB(255, 255, 255)
  117.        
  118.     else
  119.         btn.TimeToNextSpin.Visible = true
  120.         btn.ImageColor3 = Color3.fromRGB(150, 150, 150)
  121.     end
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement