Basically, i have a timer in my AI server script inside of a coroutine that isn’t working. It’s supposed to fire the PursuitEvent, but it doesn’t, and it doesn’t print “time’s up” either. Here’s the script, removed some parts that were irrelevant:
local PursuitEvent = Volatile:FindFirstChild("Pursuit")
local PursuitVictim = nil
local StareVictim = nil
local IsInPursuit = false
local IsStaring = false
local ViewDistance = 50
local CurrentTime = tick()
local StareTime = 2
local EyeStareColor = Color3.new(255,0,0)
local EyeTweenInfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local EyeTween = TweenService:Create(EyeImage,EyeTweenInfo,{ImageColor3 = EyeStareColor})
local EyeTweenReverse = TweenService:Create(EyeImage,EyeTweenInfo,{ImageColor3 = Color3.new(255,255,255)})
function Staring()
local eventconnectionrunservice
local StareTimeSum = CurrentTime + StareTime
eventconnectionrunservice = RunService.Heartbeat:Connect(function()
if CurrentTime >= StareTimeSum and StareVictim ~= nil then
print("times up")
PursuitEvent:Fire()
else eventconnectionrunservice:Disconnect() return end
end)
end
local lastraypart
local PlayerFound = false
function FindPlayer()
if lastraypart ~= nil then
lastraypart:Destroy()
end
local HeadRaycast = Ray.new(VolatileHead.Position,VolatileHead.CFrame.LookVector * ViewDistance)
--[[local visualraycastpart = Instance.new("Part")
local midpoint = HeadRaycast.Origin + HeadRaycast.Direction/2
visualraycastpart.Parent = workspace
visualraycastpart.CFrame = CFrame.lookAt(midpoint, HeadRaycast.Origin)
visualraycastpart.Size = Vector3.new(0.5,0.5,HeadRaycast.Direction.Magnitude)
visualraycastpart.Anchored = true
visualraycastpart.CanCollide = false
visualraycastpart.Transparency = 0.85
lastraypart = visualraycastpart--]]
local PlayerObject, HitPosition = workspace:FindPartOnRay(HeadRaycast,VolatileHead)
if PlayerObject ~= nil and StareVictim == nil and PlayerFound == false then
local PlayerObjectHumanoid = PlayerObject.Parent:FindFirstChildOfClass("Humanoid")
if PlayerObjectHumanoid and PlayerObjectHumanoid ~= Humanoid then
IsStaring = true
EyeTween:Play()
EyeTweenReverse:Cancel()
StareVictim = PlayerObject.Parent
PlayerFound = true
coroutine.resume(coroutine.create(Staring))
print(PlayerFound)
end
end
if PlayerObject == nil then
PlayerFound = false
print(PlayerFound)
StareVictim = nil
PursuitVictim = nil
EyeTween:Cancel()
EyeTweenReverse:Play()
coroutine.resume(coroutine.create(Staring))
end
end
while wait(0.5) do
FindPlayer()
end
Let me know if there are any missing variables. Help will be much appreciated, as this is a rather picky method.