Advertisement
HowToRoblox

ClickingGameServer

Aug 23rd, 2021
1,535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. local clickCooldown = 0.05
  2. local cooldownPlrs = {}
  3.  
  4.  
  5. local dss = game:GetService("DataStoreService")
  6.  
  7. local ds = dss:GetDataStore("DATA")
  8.  
  9.  
  10. function saveData(plr)
  11.  
  12.  
  13.     local cash = plr.Stats.Cash.Value
  14.     local upgrades = plr.Stats.Upgrades.Value
  15.  
  16.     pcall(function()
  17.  
  18.         ds:SetAsync(plr.UserId .. "-Data", {cash, upgrades})
  19.     end)
  20. end
  21.  
  22.  
  23. game.Players.PlayerAdded:Connect(function(plr)
  24.  
  25.  
  26.     local statsFolder = Instance.new("Folder")
  27.     statsFolder.Name = "Stats"
  28.     statsFolder.Parent = plr
  29.  
  30.     local cash = Instance.new("IntValue")
  31.     cash.Name = "Cash"
  32.     cash.Parent = statsFolder
  33.    
  34.     local upgrades = Instance.new("IntValue")
  35.     upgrades.Name = "Upgrades"
  36.     upgrades.Parent = statsFolder
  37.  
  38.  
  39.     local cashData = nil
  40.     local upgradesData = nil
  41.  
  42.     pcall(function()
  43.  
  44.         cashData = ds:GetAsync(plr.UserId .. "-Data")[1]
  45.         upgradesData = ds:GetAsync(plr.UserId .. "-Data")[2]
  46.     end)
  47.  
  48.     cash.Value = cashData or 0
  49.     upgrades.Value = upgradesData or 1
  50. end)
  51.  
  52.  
  53. game.Players.PlayerRemoving:Connect(saveData)
  54.  
  55. game:BindToClose(function()
  56.  
  57.  
  58.     for i, plr in pairs(game.Players:GetPlayers()) do
  59.  
  60.         saveData(plr)
  61.     end
  62. end)
  63.  
  64.  
  65. game.ReplicatedStorage:WaitForChild("ClickedRE").OnServerEvent:Connect(function(plr, instruction)
  66.    
  67.    
  68.     if instruction == "Click" and not cooldownPlrs[plr] then
  69.        
  70.         cooldownPlrs[plr] = true
  71.        
  72.        
  73.         local amountToGive = plr.Stats.Upgrades.Value ^ 1.5
  74.        
  75.         plr.Stats.Cash.Value += amountToGive
  76.        
  77.        
  78.         wait(clickCooldown)
  79.         cooldownPlrs[plr] = false
  80.        
  81.        
  82.     elseif instruction == "Upgrade" then
  83.        
  84.        
  85.         local cost = (plr.Stats.Upgrades.Value + 1) ^ 4
  86.        
  87.        
  88.         if plr.Stats.Cash.Value >= cost then
  89.            
  90.             plr.Stats.Cash.Value -= cost
  91.            
  92.             plr.Stats.Upgrades.Value += 1
  93.         end
  94.     end
  95. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement