Do module scripts apply to clones of an object?

Hello, I made an enemy ai module script which I can edit to make different types of ai, but when I clone the ai from replicatedstorage, it doesn’t seem to do anything or even run the module script automatically at all? Do I need to use collectionservice for this or another method or can I somehow run the module script on all clones of a model? Please help.
Server script:

local RunService = game:GetService('RunService')
local Players = game:GetService('Players')
local PathfindingService = game:GetService('PathfindingService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local FriendlyAI = ReplicatedStorage.AI.Allies
local EnemyAI = ReplicatedStorage.AI.Enemies

local AI = require(script.AI)

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char.AncestryChanged:wait()
		game:GetService("RunService").Stepped:wait()
		char.Parent = workspace.Allies
	end)
end)

AI.new(EnemyAI["Fast Zombie"],script.R6Anims.walk.WalkAnim,'Punch')

AI.new(FriendlyAI.Noob,script.R6Anims.walk.WalkAnim,'Punch')

AI.new(FriendlyAI["Sword Noob"],script.R6Anims.walk.WalkAnim,'Sword',script.R6Anims.SwordIdle)

I assume the cloning happens in the constructor of the AI? Because I do not see the cloning happening here. Do you think you could show the constructor code?

Your code for instantiating an object from a ModuleScript from this snippet seems to be correct, assuming the arguments match up to the constructor’s parameters. Can you also confirm that there are no related errors?

No, the cloning doesn’t happen inside of the constructor of the ai, here is the constructor script (AI.new)

local Players = game:GetService('Players')
local RunService = game:GetService('RunService')
local PathfindingService = game:GetService('PathfindingService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local CollectionService = game:GetService('CollectionService')
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)
local maxDistance = math.huge
local Anims = script.Parent.R6Anims

local AI = {}
AI.__index = AI

function AI.new(NPC,WalkAnim,AttackType,idleAnim)
    spawn(function()
		local Team = NPC.Parent.Name
		local NPCProperties = setmetatable({},AI)
		local hum = NPC.Humanoid
		local humrp = NPC.HumanoidRootPart
		local WalkAnim = hum:LoadAnimation(WalkAnim)
		local RunOnce = false
		local MeleeDB = false
		local NPCHitbox = nil

		if idleAnim then
			idleAnim = hum:LoadAnimation(idleAnim)
			NPCProperties.IdleAnim = idleAnim
			idleAnim:Play()
		end

		NPC.PrimaryPart:SetNetworkOwner(nil)

		NPCProperties.NPC = NPC
		NPCProperties.Humanoid = hum
		NPCProperties.humrp = humrp
		NPCProperties.hum = hum
		NPCProperties.NPCHitbox = NPCHitbox
		NPCProperties.MeleeDB = MeleeDB
		NPCProperties.RunOnce = RunOnce
		NPCProperties.Team = Team
		NPCProperties.WalkAnim = WalkAnim
		--Pathfinding
		local CoreOfFactory = workspace.CentreOfFactory

		local function findTarget()
			local team
			if Team == 'Allies' then
				team = workspace.Enemies:GetChildren()
			else
				team = workspace.Allies:GetChildren()
			end
			local MaxDistance = 200
			local nearestTarget

			for _,enemy in pairs(team) do
				if enemy then
					if enemy.Humanoid.Health > 0 then
						local target = enemy
						local distance = (humrp.Position - target.HumanoidRootPart.Position).Magnitude

						if distance < MaxDistance then
							nearestTarget = target
							MaxDistance = distance
						end
					end
				end
			end

			return nearestTarget
		end

		local function agro()
			repeat task.wait(0.05)
				local target = findTarget()

				if target and target.HumanoidRootPart then
					local distance = (humrp.Position - target.HumanoidRootPart.Position).Magnitude

					if distance <= 3 then
						WalkAnim:Stop()
							NPCProperties.target = target
							AI[AttackType](NPCProperties)
					else
						local targetVel = target.PrimaryPart.Velocity
						local leadBy = 7
						local lead
						
						if targetVel.Magnitude < 0.1 then
							lead = Vector3.new(0, 0, 0)
						else
							lead = targetVel.Unit * leadBy
						end
						hum:MoveTo(target.PrimaryPart.Position + lead)
					end
				end
			until target == nil or target.Humanoid.Health == 0 or (humrp.Position - target.HumanoidRootPart.Position).Magnitude > maxDistance
		end

		local function walkToCore()
			local path = PathfindingService:CreatePath()

			local success, errorMessage = pcall(function()
				path:ComputeAsync(humrp.Position, CoreOfFactory.Position)
			end)
			WalkAnim:Play()
			if success and path.Status == Enum.PathStatus.Success then
				local waypoints = path:GetWaypoints()
				for _,waypoint in pairs(waypoints) do

					if waypoint.Action == Enum.PathWaypointAction.Jump then
						hum:ChangeState(Enum.HumanoidStateType.Jumping)
					end

					if findTarget() and (humrp.Position - findTarget().HumanoidRootPart.Position).Magnitude < maxDistance then
						agro()
					end

					hum:MoveTo(waypoint.Position)
					hum.MoveToFinished:Wait()
				end
			end
			WalkAnim:Stop()
		end

		walkToCore()
	end)
end

function AI.Punch(self)
	if self.MeleeDB == false then
		self.MeleeDB = true
		self.WalkAnim:Stop()
		self.NPC:SetPrimaryPartCFrame(CFrame.new(self.NPC.HumanoidRootPart.Position,self.target.HumanoidRootPart.Position))
		local AttackAnim = self.hum:LoadAnimation(Anims.Attack)
		local Damage = 15
		local delay = 1
		
		if self.RunOnce == false then
			self.RunOnce = true
			self.NPCHitbox = RaycastHitbox.new(self.NPC['Right Arm'])
			self.NPCHitbox:SetPoints(self.NPC['Right Arm'],{Vector3.new(0,0,1),Vector3.new(-1,1,3),Vector3.new(-3.5,1,3)})
		end

		AttackAnim:Play()
		self.NPCHitbox:HitStart()

		self.NPCHitbox.OnHit:Connect(function(hit,humanoid)
			if humanoid.Parent.Name ~= self.NPC.Name and not humanoid:FindFirstAncestor(self.Team) then
				humanoid:TakeDamage(Damage)
			end
		end)
		coroutine.wrap(function()
			AttackAnim.Stopped:Wait()
			self.NPCHitbox:HitStop()
			task.wait(delay)
			self.MeleeDB = false
			self.WalkAnim:Play()
		end)()
	end
end

function AI.Sword(self)
	if self.MeleeDB == false then
		self.MeleeDB = true
		self.IdleAnim:Stop()
		self.WalkAnim:Stop()
		self.NPC:SetPrimaryPartCFrame(CFrame.new(self.NPC.HumanoidRootPart.Position,self.target.HumanoidRootPart.Position))
		local AttackAnim = self.hum:LoadAnimation(Anims.Sword)
		local Damage = 15
		local delay = 1

		if self.RunOnce == false then
			self.RunOnce = true
			self.NPCHitbox = RaycastHitbox.new(self.NPC['Right Arm'])
			self.NPCHitbox:SetPoints(self.NPC['Right Arm'],{Vector3.new(0,-1,-1),Vector3.new(0,-2,-2),Vector3.new(0,-1,-3),Vector3.new(0,-2,-4),
				Vector3.new(0,-1,1),Vector3.new(0,-2,0),Vector3.new(0,-1,1)})
		end

		AttackAnim:Play()
		self.NPCHitbox:HitStart()

		self.NPCHitbox.OnHit:Connect(function(hit,humanoid)
			if humanoid.Parent.Name ~= self.NPC.Name and not humanoid:FindFirstAncestor(self.Team) then
				humanoid:TakeDamage(Damage)
			end
		end)
		coroutine.wrap(function()
			AttackAnim.Stopped:Wait()
			self.IdleAnim:Play()
			self.WalkAnim:Play()
			self.NPCHitbox:HitStop()
			task.wait(delay)
			self.MeleeDB = false
		end)()
	end
end

return AI

I just use the constructor in ReplicatedStorage on a model and then clone that model in seperate scripts

Edit: no errors in the output, I am starting work on another script maybe using collectionservice and seeing if that works, but i’m not sure.