Advertisement
CODINGGIAN

Untitled

Mar 29th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. local buttons = script.Parent.Buttons
  2. local shopping = script.Parent.Shopping
  3.  
  4. local storage = {}
  5.  
  6. local DSS = game:GetService("DataStoreService")
  7. local Bank = DSS:GetDataStore("Money")
  8.  
  9. local function hideButton(button)
  10.     button.CanTouch = false
  11.     button.Transparency = 1
  12.     button.Billboard.Enabled = false
  13. end
  14.  
  15. local function showButton(button)
  16.     button.CanTouch = true
  17.     button.Transparency = 0
  18.     button.Billboard.Enabled = true
  19. end
  20.  
  21. local function newButton(button)
  22.     local purchase
  23.     local name = button.Name
  24.  
  25.     if shopping:FindFirstChild(name) then
  26.         purchase = shopping[name]
  27.         storage[name] = purchase:Clone()
  28.         purchase:Destroy()
  29.     else
  30.         warn("Missing a purchase : " .. name)
  31.     end
  32.  
  33.     if not (name == "1") then
  34.         hideButton(button)
  35.     end
  36.  
  37.     button.Touched:Connect(function(hit)
  38.         local player = game.Players:FindFirstChild(hit.Parent.Name)
  39.  
  40.         if player then          
  41.             local purchase = storage[name]
  42.  
  43.             if purchase then
  44.                 purchase.Parent = shopping
  45.             end
  46.  
  47.             for i, element in pairs(button:GetChildren()) do
  48.                 if element.Name == "Next" then
  49.                     local buttonToShow=buttons:FindFirstChild(element.Value)
  50.  
  51.                     if buttonToShow then
  52.                         showButton(buttonToShow)
  53.                     else
  54.                         warn("Missing button: " .. element.Value)
  55.                     end
  56.                 end
  57.             end
  58.  
  59.             button:Destroy()
  60.  
  61.         end
  62.     end)
  63. end
  64.  
  65. game.Players.PlayerAdded:Connect(function(player)
  66.    
  67.     local money = Bank:GetAsync(player.UserId) or 0
  68.    
  69.     local billboardOnServer = Instance.new("Folder", game.ServerStorage)
  70.     billboardOnServer.Name = player.Name
  71.    
  72.     local moneyOnServer = Instance.new("NumberValue", billboardOnServer)
  73.     moneyOnServer.Name = "Money"
  74.     moneyOnServer.Value = money
  75.    
  76.     local billboardLocally = Instance.new("Folder", player)
  77.     billboardLocally.Name = "leaderstats"
  78.    
  79.     local moneyLocally = Instance.new("NumberValue", billboardLocally)
  80.     moneyLocally.Name = "Money"
  81.     moneyLocally.Value = money
  82.    
  83.     for i, button in pairs(buttons:GetChildren()) do
  84.         newButton(button)
  85.     end
  86.    
  87.     player:LoadCharacter()
  88.     moneyOnServer.Changed:Connect(function(number)
  89.         moneyLocally.Value = number
  90.     end)
  91.     while true do
  92.         Bank:SetAsync(player.UserId, moneyOnServer.Value)
  93.         print("Money saved!")
  94.         wait(10)
  95.     end
  96.    
  97. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement