Guest User

Loot Crate System Script

a guest
Jul 25th, 2020
2,596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. --Put Your Item Name inside--
  2.  
  3. local ItemTable = {
  4.     'YourItemName1',
  5.     'YourItemName2',
  6.     'YourItemName3',
  7.     'YourItemName4'
  8. }
  9.  
  10. local CD = script.Parent.ClickDetector
  11. local Label = script.Parent.BillboardGui.TextLabel
  12.  
  13. --Debounce Mechanism--
  14.  
  15. local Debounce = false
  16. local Stop = false
  17.  
  18.  
  19. --Put your Item inside a folder in Replicated Storage--
  20.  
  21. local RP =  game:GetService('ReplicatedStorage')
  22. local ItemStorage = RP.ItemStorage
  23.  
  24.  
  25. --Click Function--
  26.  
  27. local function onClicked(player)
  28.    
  29.     --Checking--
  30.     print('Clicked')
  31.    
  32.     --if debounce = true--
  33.     if Debounce then print('Debounce Active') return end
  34.    
  35.     Debounce = true
  36.    
  37.     --Stop = true if the function is running--
  38.     spawn(function()
  39.         wait(5)
  40.         Stop = true
  41.     end)
  42.    
  43.     math.randomseed(tick())
  44.    
  45.  
  46.     --choosing 1 item every 0.1 seconds until stop = true--
  47.     repeat
  48.        
  49.         local ItemDisplay = ItemTable[math.random(1,#ItemTable)]
  50.         Label.Text = ItemDisplay
  51.         wait(0.1)
  52.        
  53.     until Stop == true
  54.    
  55.  
  56.     --chosen item result--
  57.     local ChosenItem = Label.Text
  58.     wait(0.5)
  59.     print(ChosenItem)
  60.     Label.Text = 'You got '.. ChosenItem
  61.    
  62.  
  63.     --finding the item in the folder--
  64.     if ItemFolder:FindFirstChild(ChosenItem) then
  65.        
  66.         local cloned = ItemFolder[ChosenItem]:Clone()
  67.         cloned.Parent = player.Backpack
  68.        
  69.     end
  70.    
  71.  
  72.     --stop the debounce--
  73.     Stop = false
  74.     wait(1)
  75.     Debounce = false
  76.    
  77. end
  78.  
  79. --Run the function when you left click--
  80. CD.MouseClick:Connect(onClicked)
Advertisement
Add Comment
Please, Sign In to add comment