of     1   

MarioKartAddict
#126295484Thursday, February 20, 2014 10:32 PM GMT

How would I yield the coroutine (or am I making it wrong) when the part is touched again Likely the way I am trying to do this is wrong local timing = 0 local run = false function timing() game:service("RunService").Stepped:connect(function(time, step) timing = timing + step print(step) print(timing) end) end game.Workspace.st.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") ~= nil then if hit.Name == "HumanoidRootPart" then if not run then run = true coroutine.wrap(timing) end if run then coroutine.yield(timing) end end end end)
MarioKartAddict
#126299542Thursday, February 20, 2014 11:11 PM GMT

back
SDuke_524
#126300076Thursday, February 20, 2014 11:16 PM GMT

coroutine.yield must be called inside the coroutine function. Also whenever an event is fired it creates its own thread, so it would be much easier to not use coroutines and do something like this: local timing = 0 local run = false local timeRunning=false function timing() game:service("RunService").Stepped:connect(function(time, step) if timeRunning then timing = timing + step print(step) print(timing) end end) end game.Workspace.st.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") ~= nil then if hit.Name == "HumanoidRootPart" then if not run then run = true timeRunning=true timing() end if run then timeRunning=false end end end end)
MarioKartAddict
#126305418Friday, February 21, 2014 12:10 AM GMT

doesn't work local timing = 0 local run = false local timeRunning = false function timing() game:service("RunService").Stepped:connect(function(time, step) if timeRunning then timing = timing + step print(step) print(timing) end end) end game.Workspace.st.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") ~= nil then if hit.Name == "HumanoidRootPart" then if not run then run = true timeRunning = true timing() end if run then timeRunning = false end end end end)

    of     1