Raildex
|
  |
| Joined: 06 Dec 2009 |
| Total Posts: 934 |
|
|
| 06 Sep 2016 04:35 PM |
I want for the player to slow down to a walk whenever they attack or get attacked, when one of these two things happens a variable named runnable is set to true and launches this function, what im stuck on is getting it to countdown correctly to when they are able to run again.
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local runTimeLeft = 10
script.Parent.Runnable.Changed:connect(function() if script.Parent.Runnable.Value == true then runTimeLeft = 10 script.Parent.Runnable.Value = false print("changed") player.Character.Humanoid.WalkSpeed = 11 while runTimeLeft > 0 do runTimeLeft = runTimeLeft - 1 wait(1) print(runTimeLeft) end player.Character.Humanoid.WalkSpeed = 20 end end)
script.Parent.Runnable.Value = true
|
|
|
| Report Abuse |
|
|
|
| 06 Sep 2016 04:44 PM |
| When they starting running, use os.time() or tick() to get the current time. Then check if the difference between the startime and the current time is larger than your desired time. |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2016 04:44 PM |
| for i=10,0,-1 do print(i) wait(1) end |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2016 04:46 PM |
| for lol=1,math.huge do end |
|
|
| Report Abuse |
|
|
ByDefault
|
  |
| Joined: 25 Jul 2014 |
| Total Posts: 3197 |
|
|
| 06 Sep 2016 04:47 PM |
@Flowery - over complicating a simple solution
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local runTimeLeft = 10
script.Parent.Runnable.Changed:connect(function() if script.Parent.Runnable.Value == true then runTimeLeft = 10 script.Parent.Runnable.Value = false print("changed") player.Character.Humanoid.WalkSpeed = 11 for i = runTimeLeft,0,-1 do print(i) wait(1) end player.Character.Humanoid.WalkSpeed = 20 end end)
script.Parent.Runnable.Value = true |
|
|
| Report Abuse |
|
|
Raildex
|
  |
| Joined: 06 Dec 2009 |
| Total Posts: 934 |
|
|
| 06 Sep 2016 05:17 PM |
| @ByDefault , your version didnt work either, now its even less reliable. The problem is that each loop is counting down at different times with a for loop and a while loop counts down far faster because it counts down once for each loop everytime |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2016 05:21 PM |
@ByDefault, it's not overly complicated at all.
local lastTick = os.time()
if os.time() - lastTick < runTimeLeft then print("Woohoo") lastTick = os.time() end |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2016 05:22 PM |
local ms = 6000 local passed = tick() local counter counter = game:getService("RunService").RenderStepped:connect(function() ms = ms - (tick() - passed)*100 if ms <= 0 then ms = 0 counter:disconnect() counter = nil end print(ms) passed = tick() end)
while counter do wait() end |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2016 05:22 PM |
| gives you the milliseconds starting from 1 minute (6000 milliseconds) |
|
|
| Report Abuse |
|
|
Raildex
|
  |
| Joined: 06 Dec 2009 |
| Total Posts: 934 |
|
|
| 06 Sep 2016 05:32 PM |
I fixed it myself, i just added a second debounce check
local runTimeLeft = 10 local runningRunTime = false
script.Parent.Runnable.Changed:connect(function() if script.Parent.Runnable.Value == true then runTimeLeft = 10 script.Parent.Runnable.Value = false print("changed") player.Character.Humanoid.WalkSpeed = 11 if runningRunTime == false then runningRunTime = true while runTimeLeft > 0 do runTimeLeft = runTimeLeft - 1 wait(1) print(runTimeLeft) end player.Character.Humanoid.WalkSpeed = 21 runningRunTime = false end end end) |
|
|
| Report Abuse |
|
|