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) |