Advertisement
PrzemekV5

Program do Script w ServerScriptService

Apr 28th, 2023
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | Gaming | 0 0
  1. local dss = game:GetService("DataStoreService")
  2. local datastore = dss:GetDataStore("Data")
  3.  
  4. local startingJump = 0
  5.  
  6. local function saveData(player)
  7.     local data = {player.leaderstats.Jump.Value, player.leaderstats.Wins.Value}
  8.     datastore:SetAsync(player.UserId, data)
  9. end
  10.  
  11. local function loadData(player)
  12.     local playerData = datastore:GetAsync(player.UserId) or {0, 0}
  13.     local ls = Instance.new("Folder", player)
  14.     ls.Name = "leaderstats"
  15.     local jump = Instance.new("IntValue", ls)
  16.     jump.Name = "Jump"
  17.     jump.Value = playerData[1]
  18.     local wins = Instance.new("IntValue", ls)
  19.     wins.Value = playerData[2]
  20.     wins.Name = "Wins"
  21.     ls.Parent = player
  22. end
  23.  
  24. game.Players.PlayerRemoving:Connect(saveData)
  25.  
  26. game:BindToClose(function()
  27.     for _, player in pairs(game.Players:GetPlayers()) do
  28.         saveData(player)
  29.     end
  30. end)
  31. game.Players.PlayerAdded:Connect(loadData)
  32.  
  33. function handleWinPad(winpad)
  34.  
  35.     local onDebounce = {}
  36.     local debounceTime = 5
  37.  
  38.     winpad.Touched:Connect(function(hit)
  39.  
  40.         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  41.  
  42.         if player and not onDebounce[player] then
  43.             onDebounce[player] = true
  44.  
  45.             player:LoadCharacter()
  46.  
  47.             player.leaderstats.Jump.Value = startingJump
  48.             player.leaderstats.Wins.Value += tonumber(winpad.Name) or 1
  49.  
  50.             wait(debounceTime)
  51.             onDebounce[player] = nil
  52.         end
  53.     end)
  54. end
  55.  
  56. for _, winpad in pairs(workspace:WaitForChild("WinPads"):GetChildren()) do
  57.     handleWinPad(winpad)
  58. end
  59.  
  60. while true do
  61.     wait(1)
  62.     for _, player in pairs(game.Players:GetPlayers()) do
  63.         local playerLS = player:WaitForChild("leaderstats")
  64.         playerLS.Jump.Value += (1 + playerLS.Wins.Value)
  65.         if player.Character and player.Character:FindFirstChild("Humanoid") then
  66.             player.Character.Humanoid.JumpHeight = playerLS.Jump.Value
  67.         end
  68.     end
  69. end
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement