Im having this strange issue where I was using heartbeat and when calling disconnect it still ran a couple times after I disconnected it.
task.spawn(function()
local connection
local running = true
connection = RunService.Heartbeat:Connect(function()
task.wait(0.5)
print(canSeePlayer)
if canSeePlayer and running then
Path:Stop()
Path:Destroy()
print("path stopped") --prints like 3-5 times after disconnecting
connection:Disconnect()
connection = nil
running = false
--pathStoppedBindable:Fire()
chasePlayer(enemy)
return
end
end)
end)
That had "path stopped" being printed multiple times even though I Disconnected the connection and set running to false (second check) AND i returned it yet it still ran like 5 times. Someone suggested using a while loop so I tried
task.spawn(function()
local running = true
while running do
task.wait(0.5)
print(canSeePlayer)
if canSeePlayer and running then
Path:Stop()
Path:Destroy()
print("path stopped") --prints like 3-5 times after running becomes false
running = false
--pathStoppedBindable:Fire()
chasePlayer(enemy)
return
end
end
end)
But im still having the same problem