Script not working after cloned

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

1 Like

make the script disabled and then enable it when cloned

1 Like

I tried that, it still didnt fix the issue

How exactly are you using Dungeonify to clone your monsters?

I was reading through the source code to both SimplePath and Dungeonify and neither one seems to clone monsters, nor do they have any methods to spawn monsters throughout the map. If I could get some more context into what is going on in the generation script, I might be able to help more.

i created a room that has the monster in it using dungeonify.

Don’t do that. Spawn your monsters in, using a spawn point inside the room. It seems like an issue with Dungeonify cloning your monster and not allowing the script to run.

1 Like

It breaks whenever it is cloned or it is moved to workspace