Guest User

+1 Speed Every Second

a guest
Aug 2nd, 2024
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | Gaming | 0 0
  1. -- +1 Walkspeed Every Second, Leaderboard, Display speed, Auto save.
  2. -- MADE BY the_main_asher ON DISCORD!
  3. -- Give credits when using.
  4.  
  5.  
  6.  
  7. -- How to use:
  8. -- Put a script inside ServerScriptService and paste this script in and hit play.
  9.  
  10.  
  11.  
  12. -- This will add a NumberValue to everybody with the name of their username adding +1 every second and this will also create the textlabel thats displaying how much speed u got
  13.  
  14. local DataStoreService = game:GetService("DataStoreService")
  15. local playerDataStore = DataStoreService:GetDataStore("PlayerWalkspeedData")
  16. local Players = game:GetService("Players")
  17.  
  18. local function loadWalkspeed(player)
  19. local success, data = pcall(function()
  20. return playerDataStore:GetAsync(tostring(player.UserId))
  21. end)
  22.  
  23. if success and data then
  24. return data
  25. else
  26. return 0
  27. end
  28. end
  29.  
  30. local function createScreenGui(parent)
  31. local screenGui = Instance.new("ScreenGui")
  32. screenGui.Name = "ScreenGui"
  33. screenGui.Parent = parent
  34. return screenGui
  35. end
  36.  
  37. local function createNumberLabel(parent)
  38. local numberLabel = Instance.new("TextLabel")
  39. numberLabel.Name = "DisplayTime"
  40. numberLabel.Size = UDim2.new(0, 200, 0, 50)
  41. numberLabel.Position = UDim2.new(0.5, -100, 0, 10)
  42. numberLabel.Text = ""
  43. numberLabel.Parent = parent
  44. numberLabel.BackgroundTransparency = 1
  45. numberLabel.TextScaled = true
  46. numberLabel.Font = Enum.Font.SourceSansBold
  47. return numberLabel
  48. end
  49.  
  50. game.Players.PlayerAdded:Connect(function(player)
  51. local playerData = Instance.new("Model")
  52. playerData.Name = "PlayerData"
  53. playerData.Parent = player
  54.  
  55. local walkSpeedValue = Instance.new("NumberValue")
  56. walkSpeedValue.Name = "Walkspeed"
  57. walkSpeedValue.Value = loadWalkspeed(player) or 0
  58. walkSpeedValue.Parent = playerData
  59.  
  60. player.CharacterAdded:Connect(function(character)
  61. local humanoid = character:WaitForChild("Humanoid")
  62.  
  63. local function updateSpeed()
  64. humanoid.WalkSpeed = walkSpeedValue.Value
  65. local playerGui = player:WaitForChild("PlayerGui")
  66. local screenGui = playerGui:FindFirstChild("ScreenGui") or createScreenGui(playerGui)
  67. local numberLabel = screenGui:FindFirstChild("DisplayTime") or createNumberLabel(screenGui)
  68. numberLabel.Text = "Walkspeed: " .. walkSpeedValue.Value
  69. end
  70.  
  71. updateSpeed()
  72.  
  73. walkSpeedValue.Changed:Connect(function()
  74. updateSpeed()
  75. end)
  76.  
  77. while true do
  78. task.wait(1)
  79. walkSpeedValue.Value += 1
  80. end
  81. end)
  82. end)
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. -- This will save everything to the textlabel and the walkspeed itself
  91. local DataStoreService = game:GetService("DataStoreService")
  92. local playerDataStore = DataStoreService:GetDataStore("PlayerWalkspeedData")
  93. local Players = game:GetService("Players")
  94.  
  95. local function saveWalkspeed(player, value)
  96. pcall(function()
  97. playerDataStore:SetAsync(tostring(player.UserId), value)
  98. end)
  99. end
  100.  
  101. game.Players.PlayerAdded:Connect(function(player)
  102. player.CharacterRemoving:Connect(function()
  103. local walkSpeedValue = player:WaitForChild("PlayerData"):WaitForChild("Walkspeed")
  104. saveWalkspeed(player, walkSpeedValue.Value)
  105. end)
  106. end)
  107.  
  108. for _, player in ipairs(Players:GetPlayers()) do
  109. game.Players.PlayerAdded:Fire(player)
  110. end
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. -- This will add a leaderboard and will save the walkspeed on the leaderboard
  118. local DataStoreService = game:GetService("DataStoreService")
  119. local playerDataStore = DataStoreService:GetDataStore("PlayerWalkspeedData")
  120. local Players = game:GetService("Players")
  121.  
  122. local function saveWalkspeed(player, value)
  123. pcall(function()
  124. playerDataStore:SetAsync(tostring(player.UserId), value)
  125. end)
  126. end
  127.  
  128. local function loadWalkspeed(player)
  129. local success, data = pcall(function()
  130. return playerDataStore:GetAsync(tostring(player.UserId))
  131. end)
  132.  
  133. if success and data then
  134. return data
  135. else
  136. return 16
  137. end
  138. end
  139.  
  140. local function updateLeaderboard(player, value)
  141. local leaderstats = player:FindFirstChild("leaderstats") or Instance.new("Folder")
  142. leaderstats.Name = "leaderstats"
  143. leaderstats.Parent = player
  144.  
  145. local walkspeedStat = leaderstats:FindFirstChild("Walkspeed") or Instance.new("IntValue")
  146. walkspeedStat.Name = "Walkspeed"
  147. walkspeedStat.Parent = leaderstats
  148. walkspeedStat.Value = value
  149. end
  150.  
  151. game.Players.PlayerAdded:Connect(function(player)
  152. local walkSpeedValue = Instance.new("NumberValue")
  153. walkSpeedValue.Name = "Walkspeed"
  154. walkSpeedValue.Value = loadWalkspeed(player)
  155. walkSpeedValue.Parent = player
  156.  
  157. updateLeaderboard(player, walkSpeedValue.Value)
  158.  
  159. player.CharacterAdded:Connect(function(character)
  160. local humanoid = character:WaitForChild("Humanoid")
  161.  
  162. humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
  163. walkSpeedValue.Value = humanoid.WalkSpeed
  164. updateLeaderboard(player, walkSpeedValue.Value)
  165. saveWalkspeed(player, walkSpeedValue.Value)
  166. end)
  167. end)
  168.  
  169. player.CharacterRemoving:Connect(function()
  170. saveWalkspeed(player, walkSpeedValue.Value)
  171. walkSpeedValue:Destroy()
  172. end)
  173. end)
  174.  
  175. for _, player in ipairs(Players:GetPlayers()) do
  176. game.Players.PlayerAdded:Fire(player)
  177. end
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment