The time marker is not going up after leaving the safezone and I assume the coroutine isn’t running because the print isn’t going. Can anyone help?
local safeCheck = coroutine.wrap(function()
while task.wait(1) do
game.Workspace.Safezone.Touched:Connect(function(hmn)
return true
end)
game.Workspace.Safezone.TouchEnded:Connect(function(hmn)
print("Hi")
return false
end)
end
end)
local timeMaker = coroutine.wrap(function()
if safeCheck() == false then
while task.wait(1) do
time.Value += 1
end
end
end)
timeMaker()
safeCheck()
You don’t have to constantly connect those events every few seconds. For one, you’re creating more unnecessary memory leaks and two it might be the reason why your code fails.
Why are you constantly connecting the events in a loop? You should only connect them once. You can use a BoolValue and change its value whenever one of the events is fired, and then you code the conditional statement depending on the BoolValue.
local timeMaker = coroutine.wrap(function()
if safe == false then
while task.wait(1) do
time.Value = time.Value + 1
end
end
end)
timeMaker()
while task.wait(1) do
game.Workspace.Safezone.Touched:Connect(function(hmn)
safe = true
end)
game.Workspace.Safezone.TouchEnded:Connect(function(hmn)
print("Hi")
safe = false
end)
end
while task.wait(1) do
if safe == false then
time.Value = time.Value + 1
end
game.Workspace.Safezone.Touched:Connect(function(hmn)
safe = true
end)
game.Workspace.Safezone.TouchEnded:Connect(function(hmn)
print("Hi")
safe = false
end)
end
The line gets me the error “attempt to index function with ‘Value’” and i do not know how to fix it. Can you help once again
What is with the time instance? What does it contain? Also you’re not even listening to me at this point, you’re still connecting the events constantly.
It seems like the time term is a global variable. In other words, use another name for it because the word time just so happens to collide with a global function.