So... Here is my sprint script it is somehow working buti feel like that it can be better?
Asked by
6 years ago Edited 6 years ago
01 | local mouse = game.Players.LocalPlayer:GetMouse() |
05 | for _, kid in ipairs (script.Parent:GetChildren()) do |
06 | if kid.className = = "Tool" then return kid end |
12 | mouse.KeyDown:connect( function (key) |
13 | key = string.lower(key) |
14 | if string.byte(key) = = 48 then |
16 | local keyConnection = mouse.KeyUp:connect( function (key) |
17 | if string.byte(key) = = 48 then |
21 | game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = game.Players.LocalPlayer.Stats.Agility.Value + 30 |
22 | repeat wait () until running = = false or game.Players.LocalPlayer.Stamina.Value < = 0 |
23 | keyConnection:disconnect() |
24 | game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 |
28 | mouse.KeyDown:connect( function (key) |
29 | key = string.lower(key) |
30 | if string.byte(key) = = 48 then |
32 | while running = = true and game.Players.LocalPlayer.Stamina.Value > 0 do |
33 | game.Players.LocalPlayer.Stamina.Value = game.Players.LocalPlayer.Stamina.Value- 2 |
35 | if game.Players.LocalPlayer.Stamina.Value < = 2 then |
36 | game.Players.LocalPlayer.Stamina.Value = 0 |
It sprints based on player's agility and drains the player's stamina by 2 every 1/10th of a second(second block of code)
Experimented until it worked, but I have a strong feeling that there will be a bug somewhere and it can be improved