Skriptten
|
  |
| Joined: 27 Sep 2010 |
| Total Posts: 244 |
|
|
| 03 Nov 2015 05:53 AM |
The issue with my script is that the function is called more than once, is there a way to make sure it could only be called once? (Ignore the print statments, they're meant to test the script and tell me where they break)
local player = script.Parent.Parent local mouse = player:GetMouse() x = 0 stop = false mouse.KeyDown:connect (function (run) if (run == "0") then if script.Stamina.Value > 20 then print("running") script.Run.Value = true repeat print(x.. " " ..script.Stamina.Value) if x < 10 then x = x + 1 end script.Stamina.Value = script.Stamina.Value - 1 player.Character.Humanoid.WalkSpeed = 16+x game.Workspace.Camera.FieldOfView = 70+x wait(0.01) until script.Run.Value == false or script.Stamina.Value <= 0 stop() else print"No stam :c" end end end) function stop() print"Stopping" script.Run.Value = false repeat print(x.. " " ..script.Stamina.Value) x = x - 1 player.Character.Humanoid.WalkSpeed = 16+x game.Workspace.Camera.FieldOfView = 70+x wait() until x <= 0 or script.Run.Value == true x = 0 wait(2) repeat if script.Stamina.Value < 100 then script.Stamina.Value = script.Stamina.Value + 1 end wait(0.5) until script.Run.Value == true or script.Stamina.Value >= 100 end
mouse.KeyUp:connect (function (letgo) if (letgo == "0") then stop() end end) |
|
|
| Report Abuse |
|
|
Skriptten
|
  |
| Joined: 27 Sep 2010 |
| Total Posts: 244 |
|
|
| 03 Nov 2015 05:55 AM |
| For clarification, when the user spams Left Shift the stam regen is multiplied by the times they've pressed left shift. |
|
|
| Report Abuse |
|
|
|
| 03 Nov 2015 05:58 AM |
| well, you called 2 different mouse functions.. i know from recent experience you cannot call mouse:connect more than once, at least when dealing with clicking, so therefore it also must affect for buttons pressed as well. |
|
|
| Report Abuse |
|
|
Skriptten
|
  |
| Joined: 27 Sep 2010 |
| Total Posts: 244 |
|
|
| 03 Nov 2015 06:01 AM |
Scott, you're right! :D Except one problem, how do I stop now? Lol
mouse.KeyUp:connect (function (letgo) -- Stops running, pretty important if (letgo == "0") then stop() end end) |
|
|
| Report Abuse |
|
|
Skriptten
|
  |
| Joined: 27 Sep 2010 |
| Total Posts: 244 |
|
|
| 03 Nov 2015 06:03 AM |
| Nvm, it still does the same thing when I spam left shift :p |
|
|
| Report Abuse |
|
|
|
| 03 Nov 2015 06:12 AM |
| change letgo to an actual function and call it in the first function. |
|
|
| Report Abuse |
|
|
Skriptten
|
  |
| Joined: 27 Sep 2010 |
| Total Posts: 244 |
|
|
| 03 Nov 2015 06:34 AM |
Well I tried something... similar and got interesting results xD When I ran this my screen shook as if my character was at a Friday night frat party
local player = game.Players.LocalPlayer local mouse = player:GetMouse() x = 0 stop = false mouse.KeyDown:connect (function (run) if (run == "0") then if script.Stamina.Value > 20 then print("running") script.Run.Value = true repeat print(x.. " " ..script.Stamina.Value) if x < 10 then x = x + 1 end script.Stamina.Value = script.Stamina.Value - 1 player.Character.Humanoid.WalkSpeed = 16+x game.Workspace.Camera.FieldOfView = 70+x wait(0.01) mouse.KeyUp:connect (function (letgo) if (letgo == "0") then stop() end end) until run == false or script.Stamina.Value <= 0 stop() else print"No stam :c" end end end) function stop() print"Stopping" script.Run.Value = false repeat print(x.. " " ..script.Stamina.Value) if x < 0 then break end x = x - 1 player.Character.Humanoid.WalkSpeed = 16+x game.Workspace.Camera.FieldOfView = 70+x wait() until x <= 0 or script.Run.Value x = 0 wait(2) repeat if script.Stamina.Value < 100 then script.Stamina.Value = script.Stamina.Value + 1 end wait(0.5) until script.Run.Value or script.Stamina.Value >= 100 end |
|
|
| Report Abuse |
|
|
| |
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
| |
|