After getting this error roblox studio completely crashes, which is well obviously quite bad. It doesn’t appear 100% of the time but it does appear. I think its due to this script:
local Folder = workspace.Zombies
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {Folder,Character}
local pathfindingservice = game:GetService("PathfindingService")
local path:Path = pathfindingservice:CreatePath({
AgentCanClimb = true,
AgentCanJump = true,
Costs = {
Border = 0
}
})
local db = {}
local dmgdb = false
local function AutoJump(zombie)
local HRP = zombie:FindFirstChild("HumanoidRootPart")
if HRP then
local origin = HRP.Position
local dir = zombie.HumanoidRootPart.CFrame.LookVector
local ray = workspace:Raycast(origin,dir,params)
if ray then
zombie.Humanoid.Jump = true
end
end
end
local function DirectMovement(zombie,pos)
zombie.Humanoid:MoveTo(pos)
AutoJump(zombie)
end
local function getzombie(obj)
for i,v in pairs(obj:GetChildren()) do
if v:FindFirstChild("Humanoid") then
return v
end
end
return nil
end
local stillsincetick = tick()
local function PathfindingMovement(zombie,pos)
task.spawn(function()
if not table.find(db,zombie) then
table.insert(db,zombie)
local waypoints
local reachedConnection
local blockedConnection
local nextWaypointIndex
local success, errorMessage = pcall(function()
path:ComputeAsync(zombie.HumanoidRootPart.Position, pos)
end)
if success and path.Status == Enum.PathStatus.Success then
-- Get the path waypoints
waypoints = path:GetWaypoints()
-- Detect if path becomes blocked
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
-- Check if the obstacle is further down the path
if blockedWaypointIndex >= nextWaypointIndex then
-- Stop detecting path blockage until path is re-computed
blockedConnection:Disconnect()
-- Call function to re-compute new path
PathfindingMovement(pos)
end
end)
-- Detect when movement to next waypoint is complete
if not reachedConnection then
reachedConnection = zombie.Humanoid.MoveToFinished:Connect(function(reached)
if reached and nextWaypointIndex < #waypoints then
-- Increase waypoint index and move to next waypoint
nextWaypointIndex += 1
if waypoints[nextWaypointIndex] then
zombie.Humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
end
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2
if waypoints[nextWaypointIndex] then
zombie.Humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
end
else
PathfindingMovement(zombie,pos)
end
table.remove(db,table.find(db,zombie))
end
end)
end
local function Update()
for i,v in pairs(Folder:GetChildren()) do
if v and v:IsA("Vector3Value") then
local owner = v:FindFirstChild("Owner")
if owner then
if owner.Value == Player then
local zombie = getzombie(v)
if zombie then
local zombiehrp = zombie:FindFirstChild("HumanoidRootPart")
local zombiehum = zombie:FindFirstChild("Humanoid")
if zombiehrp and zombiehum then
if zombiehum.Health > 0 then
local origin = zombiehrp.Position
local direction = CFrame.new(origin,v.Value).LookVector*(origin-v.Value).Magnitude
local ray = workspace:Raycast(origin,direction,params)
if ray then
PathfindingMovement(zombie,v.Value)
else
if tick()-stillsincetick > 2 then
PathfindingMovement(zombie,v.Value)
else
DirectMovement(zombie,v.Value)
end
end
if zombiehrp.Velocity.Magnitude > 1 then
stillsincetick = tick()
end
local damage = zombie:FindFirstChild("Damage")
damage = damage and damage.Value or 20
for i,v in pairs(game.Players:GetPlayers()) do
if v:DistanceFromCharacter(origin) < 7 and not v.Revive.Value then
if not dmgdb then
dmgdb = true
game.ReplicatedStorage.RemoteEvents.DamagePlayer:FireServer(v,damage)
task.wait(1.5)
dmgdb = false
end
end
end
end
end
end
end
end
end
end
end
game:GetService("RunService").RenderStepped:Connect(function()
Update()
end)
This script is a local script in StarterCharacterScripts. It handles zombie movement in my game. I have this because of optimization purposes.
Any idea on how to not get the error?