The Reached event fires twice for some reason, I tried adding debounce already. I just want it to fire once
This event is from SimplePath: SimplePath - Pathfinding Module
local Rs = game:GetService("ReplicatedStorage")
local NoiseEvent = Rs:WaitForChild("Events"):WaitForChild("PlayerNoiseEvent")
local SimplePath = require(Rs.SimplePath)
local Dummy = workspace.BlindMonster3
local state = "patrol"
local waypoints = workspace:WaitForChild("Waypoints"):GetChildren()
local Path = SimplePath.new(Dummy)
Path.Visualize = true
local Goal = Dummy.PrimaryPart.Position
NoiseEvent.OnServerEvent:Connect(function(plr, sound, pos)
print(plr, sound, pos)
Goal = pos
state = "chase"
print(state)
end)
local function patrol()
if Path.Status == "Active" then return end
if state == "chase" then return end
print("patrolling")
local ranPoint = waypoints[math.random(1, #waypoints)]
Goal = ranPoint.Position
end
Path.Reached:Connect(function()
if state == "patrol" then
patrol()
print("test")
elseif state == "chase" then
state = "patrol"
end
end)
while true do
Path:Run(Goal)
end
So basically if its state is chase it will switch to patrol when path is reached, for some reason it fires twice when switching to patrol mode