I was using dungeonify to make a dungeon with a monster, and when the monster is created, it doesnt work. After some testing, i learned that it was because dungeonify cloned the monster, which causes the pathfinding not to work. The pathfinding uses the module simplepath to work
heres the script:
if not (script.ClassName == "Script" and script.RunContext == Enum.RunContext.Legacy) then error("Script is most likely client-sided") end
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local RANGE = 1000000
local SimplePath = require(game.ServerScriptService.SimplePath)
local npc = script.Parent
local humanoid = npc.Humanoid
local connection
print("starting loop")
while task.wait(0.1) do
for _, player in Players:GetPlayers() do
if player.Character and (player.Character.PrimaryPart.Position - npc.HumanoidRootPart.Position).Magnitude <= RANGE then
print("player detected")
local path = SimplePath.new(npc)
path.Visualize = false
path:Run(player.Character.PrimaryPart.Position)
print("running")
if connection then continue end -- To prevent rewriting the Blocked connection
connection = path.Blocked:Once(function()
print("blocked")
path:Run(player.Character.PrimaryPart.Position)
connection = nil
end)
end
end
wait(1)
end
modules: SimplePath - Pathfinding Module
Dungeonify - Large templated structure generator with quotas and restrictions