Advertisement
SxScripting

Level System [Server]

Feb 27th, 2023
1,194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local RepllicatedStorage = game:GetService("ReplicatedStorage")
  3. local DSS = game:GetService("DataStoreService"):GetDataStore("SxScripting")
  4.  
  5. game.Players.PlayerAdded:Connect(function(Player)
  6. -- Varaibles --
  7. local Character = Player.Character or Player.CharacterAdded:Wait()
  8. local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
  9.  
  10. -- BASICS --
  11. local statFolder = Instance.new("Folder", Player)
  12. statFolder.Name = "statFolder";
  13.  
  14. local currentEXP = Instance.new("IntValue", statFolder)
  15. currentEXP.Name = "currentExp";
  16.  
  17. local maxEXP = Instance.new("IntValue", statFolder);
  18. maxEXP.Name = "maxEXP"
  19. maxEXP.Value = 100;
  20.  
  21. local Level = Instance.new("IntValue", statFolder)
  22. Level.Name = "Level";
  23. Level.Value = 1;
  24.  
  25. local Presitge = Instance.new("IntValue", statFolder)
  26. Presitge.Name = "Prestige"
  27. Presitge.Value = 0;
  28.  
  29. -- EXTRA --
  30. local StatPoints = Instance.new("IntValue",statFolder)
  31. StatPoints.Name = "StatPoints";
  32. StatPoints.Value = 10;
  33.  
  34. local newSpeed = Instance.new("IntValue", statFolder)
  35. newSpeed.Name = "Speed";
  36. newSpeed.Value = 16;
  37.  
  38. local newHealth = Instance.new("IntValue",statFolder)
  39. newHealth.Name = "Health";
  40. newHealth.Value = 100;
  41.  
  42. local newPower = Instance.new("IntValue", statFolder)
  43. newPower.Name = "Power";
  44. newPower.Value = 0;
  45.  
  46. local Success, Value = pcall(function()
  47. return DSS:GetAsync(Player.UserId)
  48. end)
  49.  
  50. if Success then
  51. warn("YES")
  52. if Value then
  53. warn(Value)
  54. for i,v in pairs(Value) do
  55. local currentValues = statFolder:FindFirstChild(i)
  56. if not currentValues then continue end
  57. currentValues.Value = v
  58. end
  59. else
  60. warn("NO")
  61. end
  62. else
  63. warn("NO")
  64. end
  65.  
  66. currentEXP.Changed:Connect(function()
  67. if currentEXP.Value >= maxEXP.Value then
  68. local Remaining = currentEXP.Value - maxEXP.Value;
  69. currentEXP.Value = Remaining;
  70. Level.Value += 1;
  71. StatPoints.Value += 1;
  72. maxEXP.Value += math.random(50,100);
  73. end
  74. end)
  75.  
  76. RunService.Heartbeat:Connect(function()
  77. Humanoid.MaxHealth = newHealth.Value;
  78. Humanoid.WalkSpeed = newSpeed.Value;
  79. end)
  80. end)
  81.  
  82. game.Players.PlayerRemoving:Connect(function(Player: Player)
  83. local TableOfValues = {}
  84.  
  85. for Index,Value in pairs(Player:WaitForChild("statFolder"):GetChildren()) do
  86. TableOfValues[Value.Name] = Value.Value
  87. end
  88.  
  89. local Success, Error = pcall(function()
  90. DSS:SetAsync(Player.UserId, TableOfValues)
  91. end)
  92.  
  93. if Error then
  94. warn(Error)
  95. end
  96.  
  97. end)
  98.  
  99. game:BindToClose(function()
  100.  
  101. for i,player in pairs(game.Players:GetPlayers()) do
  102. local TableOfValues = {}
  103.  
  104. for Index,Value in pairs(player:WaitForChild("statFolder"):GetChildren()) do
  105. TableOfValues[Value.Name] = Value.Value;
  106. end
  107.  
  108. local Success, Error = pcall(function()
  109. DSS:SetAsync(player.UserId, TableOfValues)
  110. end)
  111.  
  112. if Error then
  113. warn(Error)
  114. end
  115.  
  116. end
  117.  
  118. end)
  119.  
  120. RepllicatedStorage.Events.statChecker.OnServerInvoke = function(Player: Player, statTitle: TextLabel, AddPoints)
  121. local statFolder = Player:WaitForChild("statFolder")
  122. local StatPoints = statFolder.StatPoints;
  123.  
  124. if StatPoints.Value >= 1 then
  125. StatPoints.Value -= 1;
  126. statFolder[statTitle.Name].Value += 1;
  127. return true
  128. end
  129. return false;
  130. end
  131.  
  132.  
  133. local Debounce: {} = {}
  134. local Combo = {};
  135. RepllicatedStorage.Events.Punches.OnServerEvent:Connect(function(Player)
  136. if Debounce[Player] then return end
  137. Debounce[Player] = true
  138.  
  139. if not Combo[Player] then Combo[Player] = 0; end
  140. Combo[Player] += 1;
  141.  
  142. local Animations = {
  143. RepllicatedStorage.Animations.M1;
  144. RepllicatedStorage.Animations.M2;
  145. RepllicatedStorage.Animations.M3;
  146. RepllicatedStorage.Animations.M4;
  147. RepllicatedStorage.Animations.M5;
  148. }
  149. local Character = Player.Character or Player.CharacterAdded:Wait()
  150. local Humanoid = Character:WaitForChild("Humanoid")
  151.  
  152. Humanoid:LoadAnimation(Animations[Combo[Player]]):Play();
  153. Player:WaitForChild("statFolder").currentExp.Value += 10;
  154.  
  155.  
  156. if Combo[Player] == #Animations then
  157. Combo[Player] = 0;
  158. end
  159.  
  160. task.wait(.4)
  161. Debounce[Player] = nil;
  162. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement