Having Issues With OOP

Hello, I am looking to make an OOP module for my NPC that allow them to spawn and follow players as needed. I have accomplished the first half of that goal by having them spawn and setup. What I’m having issues with is the following portion.
This is what I have in my OOP Module Script:

local NPC = {}
NPC.__index = NPC

local Announce = {"RedHair","LightMan","MagmaMan","IceMan","WhiteStache","DarkBeard","DoughMan","GravityMan","ThreeSwordMan"}

local Bosses = {"RedHair","AxeHandMan","LightMan","MagmaMan","IceMan","BlackLeg","BanditLeader","LightningMan","SmokeMan","WhiteStache","DarkBeard","DoughMan","SandMan","CatCaptain","ClownCaptain","AmazonQueen","OneSwordMaster","TwoSwordMasterPrisoner","PWLightMan","SharkMan","RokushikiMasterMarine","GravityMan","ThreeSwordMan"}

local AlsoRewardable = {"ChefMaster","AmazonWarrior","AngryVillager","Bandit","RookieMarine","Fishman","FishmanBrute","SkyGuard","ArmedMarine","Celestial","ClownPirate"}

local TS = game:GetService("TweenService")

local Logic = require(game.ServerScriptService:FindFirstChild("MainHandler"))

local rewards = require(game.ServerScriptService:FindFirstChild("Rewards"))

local NPCSkillSets = {Barrier = {"BarrierPistol","Barrier"},
Bomb = {"BombDetonate","BombParty"},
Invisible = {"Invisible"},
Fire = {"FireBall","FireErruption","FireBugs","FireStream","FireConqueror"},
Ice = {"IceSpikes","IceShards","IceBird","IceSpear","IceOverhaul"},
Dark = {"DarkBall","DarkVortex","DarkPortal","BlackWorld","BlackHole"},
Light = {"LightBullet","LightRain","LightKick","LightMirror"},
Quake = {"AirCrack","AirSlam","QuakeBall","SeaQuake"},
Lightning = {"LightningBall","ThunderClap","ThunderFlash","ThunderBeam","ThunderBomb"},
Sand = {"SandBall","Spada","SandTornado","SandStorm"},
Mochi = {"MochiPunch","MochiGatling","MochiHotShot","MochiPummel"},
Magma = {"MagmaPunch","MagmaBarrage","MagmaFloor"},
Love = {"KissPistol","MeroKicks","MeroMellow"},
Gravity = {"GravityPush","GravityField","DarkNebula","MeteorShower","GrandMeteor"},
Chop = {"ChopRibbon","ChopCannon","ChopCircus"}}

local SwordSkillSets = {OneSS = {"TigerRoar","ThirtySixTons","Hiryu"},
TwoSS = {"Taka","Kuru","SeventyTwoTons"},
ThreeSS = {"DragonCutter","OnehundredEightTons","TwistingDragon"},
Bisento = {"BisentoSlam"},
Gryphon = {"ObscurePresence","DivinePillars","DivineRupture"}}

local CombatSkillSets = {Regular = {"GroundSlam"},
BlackLeg = {"DarkStepHandstandKick","DarkStepShootingKick","DarkStepSpinKick","DemonMode"},
HakiCombat = {"HakiFlowingFist","HakiUppercut"},
Rokushiki = {"Soru","HandPistol","AirBladeKick","PistolFlow"}}

local ChargeAnimations = {Barrier = {BarrierPistol = {game.ReplicatedStorage.SkillAnimations.Barrier.BarrierPistolCharge,game.ReplicatedStorage.SkillAnimations.Barrier.BarrierPistolRelease}},
Bomb = {BombDetonate = {game.ReplicatedStorage.SkillAnimations.Bomb.BombCharge,game.ReplicatedStorage.SkillAnimations.Bomb.BombRelease},
BombParty = {game.ReplicatedStorage.SkillAnimations.Bomb.BombCharge,game.ReplicatedStorage.SkillAnimations.Bomb.BombRelease}},
Invisible = {},
Fire = {FireBall = {game.ReplicatedStorage.SkillAnimations.Fire.FireArmCharge,game.ReplicatedStorage.SkillAnimations.Fire.FireArmRelease},
FireErruption = {game.ReplicatedStorage.SkillAnimations.Fire.FireErruptionCharge,game.ReplicatedStorage.SkillAnimations.Fire.FireErruptionRelease},
FireBugs = {game.ReplicatedStorage.SkillAnimations.Fire.FireFlyCharge,game.ReplicatedStorage.SkillAnimations.Fire.FireFlyRelease},
FireConqueror = {game.ReplicatedStorage.SkillAnimations.Fire.FireConquerorCharge,game.ReplicatedStorage.SkillAnimations.Fire.FireConquerorRelease}},
Ice = {IceSpikes = {game.ReplicatedStorage.SkillAnimations.Ice.IceStompCharge,game.ReplicatedStorage.SkillAnimations.Ice.IceStompRelease},
IceShards = {game.ReplicatedStorage.SkillAnimations.Ice.IceShardCharge,game.ReplicatedStorage.SkillAnimations.Ice.IceShardRelease},
IceBird = {game.ReplicatedStorage.SkillAnimations.Ice.IceBirdCharge,game.ReplicatedStorage.SkillAnimations.Ice.IceBirdRelease},
IceSpear = {game.ReplicatedStorage.SkillAnimations.Ice.IceSpearCharge,game.ReplicatedStorage.SkillAnimations.Ice.IceSpearRelease},
IceOverhaul = {game.ReplicatedStorage.SkillAnimations.Ice.IceOverhaulCharge,game.ReplicatedStorage.SkillAnimations.Ice.IceOverhaulRelease}},
Dark = {DarkBall = {game.ReplicatedStorage.SkillAnimations.Dark.DarkArmCharge,game.ReplicatedStorage.SkillAnimations.Dark.DarkArmRelease},
DarkVortex = {game.ReplicatedStorage.SkillAnimations.Dark.DarkArmCharge,game.ReplicatedStorage.SkillAnimations.Dark.DarkArmRelease},
DarkPortal = {game.ReplicatedStorage.SkillAnimations.Dark.DarkPortalCharge,game.ReplicatedStorage.SkillAnimations.Dark.DarkPortalRelease},
BlackWorld = {game.ReplicatedStorage.SkillAnimations.Dark.DarkWorldCharge,game.ReplicatedStorage.SkillAnimations.Dark.DarkWorldRelease},
BlackHole = {game.ReplicatedStorage.SkillAnimations.Dark.BlackHoleCharge,game.ReplicatedStorage.SkillAnimations.Dark.BlackHoleRelease}},
Light = {LightBullet = {game.ReplicatedStorage.SkillAnimations.Light.LightArmCharge,game.ReplicatedStorage.SkillAnimations.Light.LightArmRelease},
LightRain = {game.ReplicatedStorage.SkillAnimations.Light.BothArmCharge,game.ReplicatedStorage.SkillAnimations.Light.BothArmRelease},
LightKick = {game.ReplicatedStorage.SkillAnimations.Light.LightLegCharge,game.ReplicatedStorage.SkillAnimations.Light.LightLegRelease},
LightMirror = {game.ReplicatedStorage.SkillAnimations.Light.LightMirrorCharge,game.ReplicatedStorage.SkillAnimations.Light.LightMirrorRelease}},
Quake = {AirCrack = {game.ReplicatedStorage.SkillAnimations.Quake.AirCrackCharge,game.ReplicatedStorage.SkillAnimations.Quake.AirCrackRelease},
AirSlam = {game.ReplicatedStorage.SkillAnimations.Quake.AirSlamCharge,game.ReplicatedStorage.SkillAnimations.Quake.AirSlamRelease},
QuakeBall = {game.ReplicatedStorage.SkillAnimations.Quake.AirCrackCharge,game.ReplicatedStorage.SkillAnimations.Quake.AirCrackRelease},
SeaQuake = {game.ReplicatedStorage.SkillAnimations.Quake.TsunamiCharge,game.ReplicatedStorage.SkillAnimations.Quake.TsunamiRelease}},
Lightning = {LightningBall = {game.ReplicatedStorage.SkillAnimations.Lightning.LightningArmCharge,game.ReplicatedStorage.SkillAnimations.Lightning.LightningArmRelease},
ThunderClap = {game.ReplicatedStorage.SkillAnimations.Lightning.ThunderClapCharge,game.ReplicatedStorage.SkillAnimations.Lightning.ThunderClapRelease},
ThunderBeam = {game.ReplicatedStorage.SkillAnimations.Lightning.LightningArmCharge,game.ReplicatedStorage.SkillAnimations.Lightning.LightningArmRelease},
ThunderBomb = {game.ReplicatedStorage.SkillAnimations.Lightning.ThunderBombCharge,game.ReplicatedStorage.SkillAnimations.Lightning.ThunderBombRelease}},
Sand = {SandBall = {game.ReplicatedStorage.SkillAnimations.Sand.SandArmCharge,game.ReplicatedStorage.SkillAnimations.Sand.SandArmRelease},
Spada = {game.ReplicatedStorage.SkillAnimations.Sand.SpadaCharge,game.ReplicatedStorage.SkillAnimations.Sand.SpadaRelease},
SandTornado = {game.ReplicatedStorage.SkillAnimations.Sand.SandTornadoCharge,game.ReplicatedStorage.SkillAnimations.Sand.SandTornadoRelease},
SandStorm = {game.ReplicatedStorage.SkillAnimations.Sand.SandStormCharge,game.ReplicatedStorage.SkillAnimations.Sand.SandStormRelease}},
Magma = {MagmaPunch = {game.ReplicatedStorage.SkillAnimations.Magma.MagmaArmCharge,game.ReplicatedStorage.SkillAnimations.Magma.MagmaArmRelease},
MagmaBarrage = {game.ReplicatedStorage.SkillAnimations.Magma.MagmaArmCharge,game.ReplicatedStorage.SkillAnimations.Magma.MagmaArmRelease},
MagmaFloor = {game.ReplicatedStorage.SkillAnimations.Magma.MagmaFloorCharge,game.ReplicatedStorage.SkillAnimations.Magma.MagmaFloorRelease}},
Mochi = {MochiPunch = {game.ReplicatedStorage.SkillAnimations.Mochi.MochiPunchCharge,game.ReplicatedStorage.SkillAnimations.Mochi.MochiPunchRelease},
MochiGatling = {game.ReplicatedStorage.SkillAnimations.Mochi.MochiPunchCharge,game.ReplicatedStorage.SkillAnimations.Mochi.MochiPunchRelease},
MochiHotShot = {game.ReplicatedStorage.SkillAnimations.Mochi.MochiPunchCharge,game.ReplicatedStorage.SkillAnimations.Mochi.MochiPunchRelease},
MochiPummel = {game.ReplicatedStorage.SkillAnimations.Mochi.MochiPunchCharge,game.ReplicatedStorage.SkillAnimations.Mochi.MochiPunchRelease}},
OneSS = {TigerRoar = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("1SS"):FindFirstChild("TigerRoarCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("1SS"):FindFirstChild("TigerRoarRelease")},
ThirtySixTons = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("1SS"):FindFirstChild("36Charge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("1SS"):FindFirstChild("36Release")},
Hiryu = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("1SS"):FindFirstChild("HiryuCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("1SS"):FindFirstChild("HiryuRelease")}},
TwoSS = {Taka = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("2SS"):FindFirstChild("TakaCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("2SS"):FindFirstChild("TakaRelease")},
Kuru = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("2SS"):FindFirstChild("72Charge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("2SS"):FindFirstChild("72Release")},
SeventyTwoTons = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("2SS"):FindFirstChild("KuruCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("2SS"):FindFirstChild("KuruRelease")}},
ThreeSS = {DragonCutter = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("3SS"):FindFirstChild("DragonCutterCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("3SS"):FindFirstChild("DragonCutterRelease")},
OnehundredEightTons = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("3SS"):FindFirstChild("108Charge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("3SS"):FindFirstChild("108Release")},
TwistingDragon = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("3SS"):FindFirstChild("TwistingDragonCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("3SS"):FindFirstChild("TwistingDragonRelease")}},
Bisento = {TigerRoar = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("Bisento"):FindFirstChild("QuakeSlamCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("Bisento"):FindFirstChild("QuakeSlamRelease")}},
Gryphon = {ObscurePresence = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("Gryphon"):FindFirstChild("ObscurePresenceCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("Gryphon"):FindFirstChild("ObscurePresenceRelease")},
DivinePillars = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("Gryphon"):FindFirstChild("DivinePillarCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("Gryphon"):FindFirstChild("DivinePillarRelease")},
DivineRupture = {game.ReplicatedStorage.SkillAnimations:FindFirstChild("Gryphon"):FindFirstChild("DivineRuptureCharge"),game.ReplicatedStorage.SkillAnimations:FindFirstChild("Gryphon"):FindFirstChild("DivineRuptureRelease")}},
Love = {KissPistol = {game.ReplicatedStorage.SkillAnimations.Love.KissCharge,game.ReplicatedStorage.SkillAnimations.Love.KissRelease},
MeroKicks = {game.ReplicatedStorage.SkillAnimations.Love.SpinKickCharge,game.ReplicatedStorage.SkillAnimations.Love.SpinKickRelease},
MeroMellow = {game.ReplicatedStorage.SkillAnimations.Love.KissCharge,game.ReplicatedStorage.SkillAnimations.Love.KissRelease}},
Gravity = {GravityPush = {game.ReplicatedStorage.SkillAnimations.Gravity.PushCharge,game.ReplicatedStorage.SkillAnimations.Gravity.PushRelease},
GravityField = {game.ReplicatedStorage.SkillAnimations.Gravity.FloorCharge,game.ReplicatedStorage.SkillAnimations.Gravity.FloorRelease},
DarkNebula = {game.ReplicatedStorage.SkillAnimations.Gravity.PullCharge,game.ReplicatedStorage.SkillAnimations.Gravity.PullRelease},
MeteorShower = {game.ReplicatedStorage.SkillAnimations.Gravity.PushCharge,game.ReplicatedStorage.SkillAnimations.Gravity.PushRelease},
GrandMeteor = {game.ReplicatedStorage.SkillAnimations.Gravity.PushCharge,game.ReplicatedStorage.SkillAnimations.Gravity.PushRelease}},
Chop = {ChopRibbon = {game.ReplicatedStorage.SkillAnimations.Chop.RibbonCharge,game.ReplicatedStorage.SkillAnimations.Chop.RibbonRelease},
ChopCannon = {game.ReplicatedStorage.SkillAnimations.Chop.CannonCharge,game.ReplicatedStorage.SkillAnimations.Chop.CannonRelease},
ChopCircus = {game.ReplicatedStorage.SkillAnimations.Chop.CircusCharge,game.ReplicatedStorage.SkillAnimations.Chop.CircusRelease}},
Regular = {GroundSlam = {game.ReplicatedStorage.CombatAnimations.Regular.GroundSlamStart,game.ReplicatedStorage.CombatAnimations.Regular.GroundSlamFinish}},
HakiCombat = {HakiFlowingFist = {game.ReplicatedStorage.CombatAnimations.HakiCombat.GutPunchStart,game.ReplicatedStorage.CombatAnimations.HakiCombat.GutPunchRelease},
HakiUppercut = {game.ReplicatedStorage.CombatAnimations.HakiCombat.UpperCutStart,game.ReplicatedStorage.CombatAnimations.HakiCombat.UpperCutRelease}},
Rokushiki = {HandPistol = {game.ReplicatedStorage.CombatAnimations.Rokushiki.FingerPistolStart,game.ReplicatedStorage.CombatAnimations.Rokushiki.FingerPistolRelease},
AirBladeKick = {game.ReplicatedStorage.CombatAnimations.Rokushiki.AirBladeStart,game.ReplicatedStorage.CombatAnimations.Rokushiki.AirBladeRelease},
PistolFlow = {game.ReplicatedStorage.CombatAnimations.Rokushiki.RokuoganStart,game.ReplicatedStorage.CombatAnimations.Rokushiki.RokuoganRelease}},
BlackLeg = {DarkStepHandstandKick = {game.ReplicatedStorage.CombatAnimations.BlackLeg.HandStandCharge,game.ReplicatedStorage.CombatAnimations.BlackLeg.HandStandRelease},
DarkStepShootingKick = {game.ReplicatedStorage.CombatAnimations.BlackLeg.ShootingKickCharge,game.ReplicatedStorage.CombatAnimations.BlackLeg.ShootingKickRelease},
DarkStepSpinKick = {game.ReplicatedStorage.CombatAnimations.BlackLeg.SpinKickCharge,game.ReplicatedStorage.CombatAnimations.BlackLeg.SpinKickRelease},}}

local function Gyro(Opt,Selected,OnlySides,Targ,AI)
	local ATT
	local ATT2
	local CurrentPos
	local CurrentGyro
	coroutine.wrap(function()
		if Opt == "Create" then
			ATT = Instance.new("Attachment",AI.HumanoidRootPart)
			ATT2 = Instance.new("Attachment",game.Workspace.Terrain)
			CurrentPos = Instance.new("AlignPosition",ATT)
			CurrentPos.Position = AI.HumanoidRootPart.Position
			CurrentPos.Mode = Enum.PositionAlignmentMode.OneAttachment
			CurrentPos.Attachment0 = ATT
			CurrentPos.RigidityEnabled = true
			CurrentPos.Parent = AI.HumanoidRootPart
			CurrentPos.ApplyAtCenterOfMass = true
			CurrentGyro = Instance.new("AlignOrientation",ATT)
			CurrentGyro.Mode = Enum.OrientationAlignmentMode.OneAttachment
			CurrentGyro.Attachment0 = ATT
			CurrentGyro.RigidityEnabled = true
			coroutine.wrap(function()
				while ATT and ATT2 and wait() do
					if ATT ~= nil and ATT2 ~= nil then
						if OnlySides ~= nil then
							CurrentGyro.CFrame = CFrame.lookAt(AI.HumanoidRootPart.Position,Targ.Position * Vector3.new(1,0,1)
								+ AI.HumanoidRootPart.Position * Vector3.new(0,1,0))
						else
							CurrentGyro.CFrame = CFrame.new(AI.HumanoidRootPart.Position,Targ.Position)
						end
					end
				end
			end)()
		elseif Opt == "Stop" then
			if CurrentPos ~= nil then
				CurrentPos:Destroy()
			end
			if CurrentGyro ~= nil then
				CurrentGyro:Destroy()
			end
			if ATT ~= nil then
				ATT:Destroy()
			end
			if ATT2 ~= nil then
				ATT2:Destroy()
			end
			ATT = nil
			ATT2 = nil
			CurrentGyro = nil
			CurrentPos = nil
		end
	end)()
end

function lerp(a, b, c)
	return a + (b - a) * c
end

function quadBezier(t, p0, p1, p2)
	local l1 = lerp(p0, p1, t)
	local l2 = lerp(p1, p2, t)
	local quad = lerp(l1, l2, t)
	return quad
end

function NPC.Haki(Weapon,NPC)
	local ObjectsTable = {}
	local HakiParts = {}
	local Mats = {}
	local HakiOn = false
	local Particles = {}
	coroutine.wrap(function()
		for i,v in pairs(NPC:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("WeaponName") then
				for i,c in pairs(v:GetDescendants()) do
					if c:IsA("BasePart") and c.Name ~= "Weld" then
						table.insert(HakiParts,c)
						local OC = Instance.new("Color3Value")
						OC.Name = "OriginalColor"
						OC.Value = c.Color
						OC.Parent = c
						local OM = Instance.new("StringValue")
						OM.Name = "OriginalMaterial"
						OM.Value = tostring(c.Material)
						OM.Parent = c
						local T = table.create(2,"")
						T[1] = c
						T[2] = c.Material
						table.insert(Mats,T)
					end
				end
			end
		end
		while wait() do
			if NPC:FindFirstChild("Humanoid") ~= nil then
				local Player = NPC
				local DFolder
					DFolder = Player:FindFirstChild("Settings")
				if Player:FindFirstChild("Invisibility") then
					for i,v in pairs(HakiParts) do
						v.Transparency = 1
						for i,b in pairs(v:GetDescendants()) do
							if b:IsA("Beam") then
								if not table.find(Particles,b) then
									table.insert(Particles,b)
								end
								for i,c in pairs(Particles) do
									c.Enabled = false
								end
							end
						end
					end
				else
					for i,c in pairs(Particles) do
						if Player:FindFirstChild("Armament") then
							if c:IsA("Beam") then
								c.Enabled = true
							end
						end
					end
					for i,v in pairs(HakiParts) do
						v.Transparency = 0
						table.clear(Particles)
					end
				end
				if Player:FindFirstChild("Armament") and HakiOn == false then
					HakiOn = true
					for i,v in pairs(HakiParts) do
						v.Material = Enum.Material["Neon"]
						v.BrickColor = BrickColor.new("Neon orange")
						local TI = TweenInfo.new(0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
						local Goal = {Color = Color3.new(0,0,0)}
						local Animation = TS:Create(v, TI, Goal)
						Animation:Play()
					end
					local HEC
						HEC = Player:WaitForChild("HakiColor")
					local RVal = HEC:FindFirstChild("R")
					local GVal = HEC:FindFirstChild("G")
					local BVal = HEC:FindFirstChild("B")
					for i,v in pairs(Weapon:GetDescendants()) do
						if v:IsA("Beam") then
							v.Color = ColorSequence.new(Color3.fromRGB(RVal.Value,GVal.Value,BVal.Value))
							v.Enabled = true
						end
						if v:IsA("ParticleEmitter") and v.Name == "HakiEffect" then
							v.Enabled = true
						end
					end
				elseif not Player:FindFirstChild("Armament") and HakiOn == true then
					HakiOn = false
					for i,v in pairs(Weapon:GetDescendants()) do
						if v:IsA("Beam") then
							v.Enabled = false
						end
						if v:IsA("ParticleEmitter") and v.Name == "HakiEffect" then
							v.Enabled = false
						end
					end
					for i,v in pairs(HakiParts) do
						for i,c in pairs(Mats) do
							if c[1] == v then
								v.Color = v:FindFirstChild("OriginalColor").Value
								v.Material = c[2]
							end
						end
					end
				end
			end
		end
	end)()
	return ObjectsTable
end

function NPC.new(NPCObj,PointCheck,RangeCheck,Respawned)
	local ObjectsTable = {}
	

	local AI = NPCObj
	local HMD = AI:WaitForChild("Humanoid")
	
	AI.ChildAdded:Connect(function(Item)
		if Item:IsA("Model") and Item:FindFirstChild("WeaponName") then
			NPC.Haki(Item,AI)
		end
	end)

		local function KeepTrack(Point,Range)
			coroutine.wrap(function()
				local I = Instance.new("ObjectValue")
				I.Name = "SpawnPoint"
				I.Value = Point
				I.Parent = AI
				local I = Instance.new("NumberValue")
				I.Name = "NPCRange"
				I.Value = Range or 75
				I.Parent = AI
			end)()
		end

		local CF = AI.HumanoidRootPart.CFrame
		local AISettings = AI:FindFirstChild("Settings")
		AI:FindFirstChild("Humanoid").MaxHealth = 50 + (AISettings:FindFirstChild("Defense").Value*5)
		AI:FindFirstChild("Humanoid").Health = AI:FindFirstChild("Humanoid").MaxHealth
		--AI:FindFirstChild("Follow").Disabled = false

		if PointCheck ~= nil and RangeCheck ~= nil and Respawned == true then
			KeepTrack(PointCheck,RangeCheck)
		end

		if table.find(Announce,AI.Name) then
			for i,Player in pairs(game.Players:GetChildren()) do
				local Notif = game.ReplicatedStorage.UI:FindFirstChild("Notif"):Clone()
				Notif.Text = "SYSTEM: "..AI.Name.." Has Spawned!"
				Notif.TextColor3 = Color3.new(1, 1, 1)
				Notif:FindFirstChild("UIGradient"):FindFirstChild("Legendary").Disabled = false
				Notif.Parent = Player.PlayerGui:WaitForChild("Main"):WaitForChild("Notifications")
			end
		end

		local Idle = AI:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(game.ReplicatedStorage.Animations.Idle)
		Idle:Play()

		coroutine.wrap(function()
			local Range = AI:WaitForChild("NPCRange").Value
			local Point = AI:WaitForChild("SpawnPoint").Value
			local SeaLevel = 130
			game:GetService("RunService").Stepped:Connect(function()
				pcall(function()
					local RangeCheck = Range or 75
					if AI:FindFirstChild("Torso") then
						local HRP = AI:FindFirstChild("Torso")
						if (HRP.Position-Point.Position).Magnitude > RangeCheck or HRP.CFrame.Y <= SeaLevel then
							HRP.CFrame = Point.CFrame
						end
					end
				end)
			end)
		end)()

		local LoadThese = {}
		for i,v in pairs(game.ReplicatedStorage:GetDescendants()) do
			if v:IsA("Animation") then
				table.insert(LoadThese,v)
			end
		end
		for i,v in pairs(LoadThese) do
			AI:FindFirstChild("Humanoid"):LoadAnimation(v)
		end

		local RunAnim



		local AIClone = AI:Clone()
		HMD.Died:connect(function()
			AI.Head:FindFirstChild("Overhead"):Destroy()
			AI.Parent = game.Lighting
			game.ServerScriptService:FindFirstChild("BindableEvents"):FindFirstChild("DeathEffect"):Fire(AI)
			wait(AISettings:FindFirstChild("RespawnTime").Value)
			if Bosses[AI.Name] then
				if game.Workspace:FindFirstChild(AI.Name) == nil then
					AIClone:MakeJoints()
					AIClone.Parent = workspace
					AIClone.HumanoidRootPart.CFrame = CF
					Logic.SpawnNPC(AIClone.Name)
					AI:Destroy()
				else
					AI:Destroy()
				end
			else
				AIClone:MakeJoints()
				AIClone.Parent = workspace
			AIClone.HumanoidRootPart.CFrame = CF
			local NPC_OOP = require(game.ServerScriptService:FindFirstChild("NPCOOP_Handler"))
			NPC_OOP.new(AI)
				AI:Destroy()
			end
		end)

		AI:FindFirstChild("Humanoid").Running:Connect(function(Speed)
			if Speed >= 3 then
				RunAnim = AI:FindFirstChild("Humanoid").Animator:LoadAnimation(game.ReplicatedStorage:FindFirstChild("Animations"):FindFirstChild("Walk"))
				RunAnim:Play()
			else
				if RunAnim then
					RunAnim:Stop()
				end
			end
		end)

		if AISettings:FindFirstChild("HakiOn").Value == true then
			local HL = AISettings:FindFirstChild("HakiLevel").Value
			local LegArmament = false
			if AISettings:FindFirstChild("FightStyle").Value == "BlackLeg" then
				LegArmament = true
			end
			local ACR = AI:FindFirstChild("HakiColor"):FindFirstChild("R")
			local ACG = AI:FindFirstChild("HakiColor"):FindFirstChild("G")
			local ACB = AI:FindFirstChild("HakiColor"):FindFirstChild("B")
			local W1
			local W2
			if LegArmament == false then
				W1 = "Right Arm"
			else
				W1 = "Right Leg"
			end
			if LegArmament == false then
				W2 = "Left Arm"
			else
				W2 = "Left Leg"
			end
			local S = game.ReplicatedStorage:FindFirstChild("Sounds"):FindFirstChild("Armament"):Clone()
			S.Parent = AI.HumanoidRootPart
			S:Play()
			game.Debris:AddItem(S,S.TimeLength)
			local RA
			local LA
			local ML
			if AI:WaitForChild("Settings"):FindFirstChild("MissingLimb").Value == true then
				ML = AI:WaitForChild("Settings"):FindFirstChild("Limb").Value
			end
			if HL == 1 then
				RA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV1"):Clone()
				LA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV1"):Clone()
			elseif HL == 2 then
				RA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV2"):Clone()
				LA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV2"):Clone()
			elseif HL == 3 then
				RA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV3"):Clone()
				LA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV3"):Clone()
			end
			if ML then
				if ML == "Right Arm" then
					RA:FindFirstChild("HakiPart").Transparency = 1
				elseif ML == "Left Arm" then
					LA:FindFirstChild("HakiPart").Transparency = 1
				end
			end
			if AISettings.HasRyou.Value == "Has" or AISettings.HasRyou.Value == true then
				local I = Instance.new("StringValue")
				I.Name = "RyouHaki"
				I.Parent = AI
				if ML ~= "Right Arm" then
					for i,v in pairs(game.ServerScriptService:FindFirstChild("Ryou_Particles"):GetChildren()) do
						local X = v:Clone()
						if X.Name == "RyouMain" then
							X.Color = ColorSequence.new(Color3.fromRGB(ACR.Value,ACG.Value,ACB.Value))
						end
						X.Parent = RA:FindFirstChild("HakiPart")
						X.Enabled = true
					end
				end
				if ML ~= "Left Arm" then
					for i,v in pairs(game.ServerScriptService:FindFirstChild("Ryou_Particles"):GetChildren()) do
						local X = v:Clone()
						if X.Name == "RyouMain" then
							X.Color = ColorSequence.new(Color3.fromRGB(ACR.Value,ACG.Value,ACB.Value))
						end
						X.Parent = LA:FindFirstChild("HakiPart")
						X.Enabled = true
					end
				end
			end
			RA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").OutlineTransparency = 1
			RA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").FillTransparency = 1
			LA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").OutlineTransparency = 1
			LA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").FillTransparency = 1
			local TI = TweenInfo.new(0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
			local Goal = {FillTransparency = 0, OutlineTransparency = 0}
			local Animation = TS:Create(RA:FindFirstChild("HakiPart"):FindFirstChild("Highlight"), TI, Goal)
			Animation:Play()
			local TI = TweenInfo.new(0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
			local Goal = {FillTransparency = 0, OutlineTransparency = 0}
			local Animation = TS:Create(LA:FindFirstChild("HakiPart"):FindFirstChild("Highlight"), TI, Goal)
			Animation:Play()
			local w = Instance.new("Weld",AI:FindFirstChild(W1))
			w.Name = "ArmamentWeld"
			w.Part0 = AI:FindFirstChild(W1)
			w.Part1 = RA:FindFirstChild("Weld")
			w.C1 = CFrame.new(0,0,0)
			RA:FindFirstChild("Weld").Anchored = false
			RA.Name = "Armament"
			RA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").OutlineColor = Color3.fromRGB(ACR.Value,ACG.Value,ACB.Value)
			RA.Parent = AI
			local w = Instance.new("Weld",AI:FindFirstChild(W2))
			w.Name = "ArmamentWeld"
			w.Part0 = AI:FindFirstChild(W2)
			w.Part1 = LA:FindFirstChild("Weld")
			w.C1 = CFrame.new(0,0,0)
			LA:FindFirstChild("Weld").Anchored = false
			LA.Name = "Armament"
			LA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").OutlineColor = Color3.fromRGB(ACR.Value,ACG.Value,ACB.Value)
			LA.Parent = AI
			local I = Instance.new("StringValue")
			I.Name = "ArmamentOn"
			I.Parent = AI
			local L = Instance.new("PointLight")
			L.Range = 12
			L.Brightness = 2
			L.Color = Color3.new(1, 0.333333, 0)
			L.Parent = AI.HumanoidRootPart
			local TI = TweenInfo.new(0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
			local Goal = {Range = 0,Brightness = 0}
			local Animation = TS:Create(L, TI, Goal)
			Animation:Play()
			game.Debris:AddItem(L,0.75)
		end

		local RaceModelNPC = {"Skypiean","Mink"}

		if table.find(RaceModelNPC,AISettings:FindFirstChild("Race").Value) then
			local RaceStuff = game.ReplicatedStorage:FindFirstChild("Race_Configurations"):FindFirstChild("RaceModels"):FindFirstChild(AISettings:FindFirstChild("Race").Value):Clone()
			for i,v in pairs(RaceStuff:GetChildren()) do
				if AI:FindFirstChild(v.Name) then
					local Wep = v
					for i,c in pairs(Wep:GetChildren()) do
						if c.Name == "Weld" then
							local w = Instance.new("Motor6D",AI:FindFirstChild(v.Name))
							w.Part0 = AI:FindFirstChild(v.Name)
							w.Part1 = Wep:FindFirstChild("Weld")
							w.C1 = CFrame.new(0,0,0)
							for i,v in pairs(Wep:GetChildren()) do
								if v:IsA("BasePart") then
									v.Anchored = false
								end
							end
						end
					end
				end
			end
			RaceStuff.Parent = AI
		end

		if AISettings:FindFirstChild("WeaponSlot").Value ~= "" then
			local Weapon = game.ReplicatedStorage.Weapons:FindFirstChild(AISettings:FindFirstChild("WeaponSlot").Value):Clone()
			local WN = Weapon.Name
			Weapon.Name = "Weapon"
			if Weapon:FindFirstChild("MultiWeld") == nil then
				local w = Instance.new("Motor6D",AI:FindFirstChild("Right Arm"))
				w.Part0 = AI:FindFirstChild("Right Arm")
				w.Part1 = Weapon:FindFirstChild("Weld")
				w.C1 = CFrame.new(0,0,0)
				for i,v in pairs(Weapon:GetChildren()) do
					if v:IsA("BasePart") then
						v.Anchored = false
					end
				end
				Weapon:FindFirstChild("Weld").Anchored = false
			else
				for i,v in pairs(Weapon:GetChildren()) do
					if AI:FindFirstChild(v.Name) then
						local Wep = v
						for i,c in pairs(Wep:GetChildren()) do
							if c.Name == "Weld" then
								local w = Instance.new("Motor6D",AI:FindFirstChild(v.Name))
								w.Part0 = AI:FindFirstChild(v.Name)
								w.Part1 = Wep:FindFirstChild("Weld")
								w.C1 = CFrame.new(0,0,0)
								for i,v in pairs(Wep:GetChildren()) do
									if v:IsA("BasePart") then
										v.Anchored = false
									end
								end
							end
						end
					end
				end
			end
			Weapon.Parent = AI
			--for i,haki in pairs(Weapon:GetDescendants()) do
			--	if haki:IsA("Script") then
			--		if haki.Name == "Haki" or haki.Name == "MultiHaki" then
			--			if AISettings:FindFirstChild("HakiOn").Value == true then
			--				haki.Disabled = false
			--			end
			--		end
			--	end
			--end
			if game.ReplicatedStorage:FindFirstChild("IdleAnimations"):FindFirstChild(AISettings:FindFirstChild("WeaponSlot").Value) ~= nil then
				local Idle = game.ReplicatedStorage:FindFirstChild("IdleAnimations"):FindFirstChild(AISettings:FindFirstChild("WeaponSlot").Value):FindFirstChild("Idle")
				local AN = AI:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(Idle)
				AN:Play()
			end
			AI:FindFirstChild("HumanoidRootPart").Anchored = false
		end

		local Acceptable = {66214495,204471960,73293890}

		AI:FindFirstChild("Humanoid").Died:Connect(function()
			for i,v in pairs(AI:FindFirstChild("EXPShare"):GetChildren()) do
				if game.Players:FindFirstChild(v.Name) then
					if v.Value >= (AI.Humanoid.MaxHealth/4) then
						local PTR = game.Players:FindFirstChild(v.Name)
						if table.find(Bosses,AI.Name) or table.find(AlsoRewardable,AI.Name) then
							if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(PTR.userId, 76813613) then
								rewards.Spin(AI.Name.."Double",1000,PTR)
							else
								rewards.Spin(AI.Name,1000,PTR)
							end
						end
						if game.ServerScriptService:FindFirstChild("EXP_Rates"):FindFirstChild(AI.Name) then
							local Rate = game.ServerScriptService:FindFirstChild("EXP_Rates"):FindFirstChild(AI.Name).Value
							if PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("Level").Value < game.ServerStorage.Caps:FindFirstChild("Level").Value then
								PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("EXP").Value += Rate
							else
								if table.find(Acceptable,PTR.UserId) then
									PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("EXP").Value += Rate
								end
							end
						end
						if game.ServerScriptService:FindFirstChild("Gold_Rates"):FindFirstChild(AI.Name) then
							local Rate
							if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(PTR.userId, 76813457) then
								Rate = (game.ServerScriptService:FindFirstChild("Gold_Rates"):FindFirstChild(AI.Name).Value*2)
							else
								Rate = game.ServerScriptService:FindFirstChild("Gold_Rates"):FindFirstChild(AI.Name).Value
							end
							if PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("Gold").Value + Rate <= game.ServerStorage.Caps:FindFirstChild("Gold").Value then
								PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("Gold").Value += Rate
							else
								if table.find(Acceptable,PTR.UserId) then
									PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("Gold").Value += Rate
								end
							end
						end
						if PTR:FindFirstChild("Quest") then
							local QF = PTR:FindFirstChild("Quest")
							if QF:FindFirstChild("Enemy").Value == AI.Name then
								QF:FindFirstChild("Defeated").Value += 1
							end
						end
					end
				end
			end
		end)

		for i,Hair in pairs(AI:GetDescendants()) do
			if Hair:IsA("BasePart") and Hair.Name == "Hair" then
				Hair.BrickColor = BrickColor.Random()
			end
		end

		local Skins = {}
		local SkinChoices = AI:FindFirstChild("Settings"):FindFirstChild("Skins"):FindFirstChild(AI:FindFirstChild("Settings"):FindFirstChild("Race").Value)
		for i,v in pairs(SkinChoices:GetChildren()) do
			table.insert(Skins,v)
		end
		local NOS = table.getn(Skins)
		local Rando = math.random(1,NOS)
		local ChosenSkin = Skins[Rando]

		for i,v in pairs(AI:GetChildren()) do
			if v.Name == "Head" or v.Name == "Torso" or v.Name == "Right Arm" or v.Name == "Right Leg" or v.Name == "Left Arm" or v.Name == "Left Leg" or v.Name == "Fin" then
				v.BrickColor = ChosenSkin.Value
			end
	end
	
	local HMD = AI:FindFirstChild("Humanoid")
	
	local larm = AI:FindFirstChild("Left Arm")
	local rarm = AI:FindFirstChild("Right Arm")
	local Folder = AI:FindFirstChild("Settings")
	local CS = game:GetService("CollectionService")
	local CF = AI.HumanoidRootPart.CFrame
	local OriginalSpeed = tonumber(AI.Humanoid.WalkSpeed)

	local LoadedAnimations = {}

	local SkillCooldown = false
	local TPCooldown = false
	local GlobalCooldown = false
	local Rolled = false

	local CombatChill = false
	local Tick1,Tick2
	local CurrentString = 0
	local AM = AI:FindFirstChild("Humanoid")
	local AnimFolder
	if Folder:FindFirstChild("WeaponSlot").Value == "" then
		AnimFolder = game.ReplicatedStorage:FindFirstChild("FightStyleAnimations"):FindFirstChild(Folder:FindFirstChild("FightStyle").Value)
	else
		AnimFolder = game.ReplicatedStorage:FindFirstChild("WeaponAnimations"):FindFirstChild(Folder:FindFirstChild("WeaponSlot").Value)
	end
	local LoopOn = false
	coroutine.wrap(function()
		repeat
			if AI:FindFirstChild("Stunned") == nil and SkillCooldown == false and AI:FindFirstChild("Staggered") == nil and CS:HasTag(AI,"Blocking") == false and CS:HasTag(AI,"UsingSkill") == false and HMD.Health > 0 then
				if #game.Players:GetPlayers() > 0 then

					local dist
					local Nearest = {}

					for i,v in pairs(game.Players:GetChildren()) do
						if v ~= nil and v.Character ~= nil then
							local CharDist = table.create(1,v.Name)
							pcall(function()	
								CharDist[2] = (v.Character.HumanoidRootPart.Position - AI.HumanoidRootPart.Position).Magnitude
								table.insert(Nearest,CharDist)
							end)
						end
					end

					if table.getn(Nearest) > 1 then
						table.sort(Nearest, 
							function(a,b)
								return tonumber(a[2])<tonumber(b[2])
							end
						)
					end

					local targettorso
					local target

					if Nearest ~= nil and Nearest[1] ~= nil and Nearest[1][1] ~= nil then -- Fixed Error by having it check Nearest[1][1] is not nil before firing below if statement no more errors
						if game.Players:FindFirstChild(Nearest[1][1]) ~= nil then -- Line Erroring due to Nil when its looking for a number.
							targettorso = game.Players:FindFirstChild(Nearest[1][1])
						else
							targettorso = nil
						end
					end
					if targettorso ~= nil then
						target = targettorso.Character:FindFirstChild("Torso")
					else
						target = nil
					end
					if HMD.Health < HMD.MaxHealth then
						local CustomDistance = {RedHair = 200,CorruptSwordsman = 200,MagmaMan = 250,LightMan = 250,IceMan = 250,DarkBeard = 250,DoughMan = 250}
						if Bosses[AI.Name] then
							dist = CustomDistance[AI.Name]
						else
							dist = 75	
							print(dist)
						end

						if AI:FindFirstChild("UsingObservation") == nil and AI:FindFirstChild("Settings"):FindFirstChild("Observation").Value == true then
							local I = Instance.new("StringValue")
							I.Name = "UsingObservation"
							I.Parent = AI

						end
					else
						dist = 0
					end
					if target ~= nil and (AI:FindFirstChild("HumanoidRootPart").Position - target.Position).Magnitude <= dist then
						AI.Humanoid:MoveTo(target.Position, target)

						-- Skills
						coroutine.wrap(function()
							if NPCSkillSets[AI.Settings.Core.Value] ~= nil and Rolled == false and SkillCooldown == false and AI.Settings.PrimarySkillSet.Value == "Core" then
								Rolled = true
								SkillCooldown = true
								local SkillOptions = table.getn(NPCSkillSets[AI.Settings.Core.Value])
								local Choose = math.random(1,SkillOptions)
								local Skill = NPCSkillSets[AI.Settings.Core.Value][Choose]
								local ChargeAnim
								local ReleaseAnim
								local TimeCharging
								if ChargeAnimations[AI.Settings.Core.Value][Skill] ~= nil then
									ChargeAnim = ChargeAnimations[AI.Settings.Core.Value][Skill][1]
									ReleaseAnim = ChargeAnimations[AI.Settings.Core.Value][Skill][2]
									TimeCharging = (math.random(10,20)/10)
								end
								if ChargeAnim ~= nil then
									Gyro("Create",nil,true,target)
									local SpecialSkill = {}
									if tostring(Skill) == "FireConqueror" or tostring(Skill) == "BlackHole" or tostring(Skill) == "IceSpear" or tostring(Skill) == "MochiSlam" or tostring(Skill) == "MochiHotShot" or tostring(Skill) == "ThunderBomb" then
										if tostring(Skill) == "MochiSlam" then
											Logic.CreateSkillEffects(AI,"MochiArm")
										elseif tostring(Skill) == "MochiHotShot" then
											Logic.CreateSkillEffects(AI,"MochiArmHot")
										else
											Logic.CreateSkillEffects(AI,tostring(Skill))
										end
									end
									local AN = LoadedAnimations[ChargeAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ChargeAnim)
									end
									AN:Play()
									AN.KeyframeReached:Connect(function(Frame)
										if Frame == "Freeze" then
											AN:AdjustSpeed(0)
										end
									end)
									task.wait(TimeCharging)
									AN:Stop()
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									local AN = LoadedAnimations[ReleaseAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ReleaseAnim)
									end
									AN:Play()
									task.wait(1)
									Gyro("Stop")
									SkillCooldown = false
								else
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									SkillCooldown = false
								end
								if tostring(Skill) ~= "Barrier" and tostring(Skill) ~= "Invisible" then
									task.wait(math.random(8,10))
								else
									if table.find(Bosses,AI.Name) == nil then
										task.wait(math.random(12,15))
									else
										task.wait(math.random(5,10))
									end
								end
								Rolled = false
							end
							if CombatSkillSets[AI.Settings.CombatSkillSet.Value] ~= nil and Rolled == false and SkillCooldown == false and AI.Settings.PrimarySkillSet.Value == "Combat" then
								Rolled = true
								SkillCooldown = true
								local SkillOptions = table.getn(CombatSkillSets[AI.Settings.CombatSkillSet.Value])
								local Choose = math.random(1,SkillOptions)
								local Skill = CombatSkillSets[AI.Settings.CombatSkillSet.Value][Choose]
								local ChargeAnim
								local ReleaseAnim
								local TimeCharging
								if ChargeAnimations[AI.Settings.CombatSkillSet.Value][Skill] ~= nil then
									ChargeAnim = ChargeAnimations[AI.Settings.CombatSkillSet.Value][Skill][1]
									ReleaseAnim = ChargeAnimations[AI.Settings.CombatSkillSet.Value][Skill][2]
									TimeCharging = (math.random(10,20)/10)
								end
								if ChargeAnim ~= nil then
									Gyro("Create",nil,true,target)
									local SpecialSkill = {}
									local AN = LoadedAnimations[ChargeAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ChargeAnim)
									end
									AN:Play()
									AN.KeyframeReached:Connect(function(Frame)
										if Frame == "Freeze" then
											AN:AdjustSpeed(0)
										end
									end)
									task.wait(TimeCharging)
									AN:Stop()
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									local AN = LoadedAnimations[ReleaseAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ReleaseAnim)
									end
									AN:Play()
									task.wait(1)
									Gyro("Stop")
									SkillCooldown = false
								else
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									SkillCooldown = false
								end
								if table.find(Bosses,AI.Name) == nil then
									task.wait(math.random(12,15))
								else
									task.wait(math.random(5,10))
								end
								Rolled = false
							end
							if SwordSkillSets[AI.Settings.WeaponSkillSet.Value] ~= nil and Rolled == false and SkillCooldown == false and AI.Settings.PrimarySkillSet.Value == "Weapon" then
								Rolled = true
								SkillCooldown = true
								local SkillOptions = table.getn(SwordSkillSets[AI.Settings.WeaponSkillSet.Value])
								local Choose = math.random(1,SkillOptions)
								local Skill = SwordSkillSets[AI.Settings.WeaponSkillSet.Value][Choose]
								local ChargeAnim
								local ReleaseAnim
								local TimeCharging
								if ChargeAnimations[AI.Settings.WeaponSkillSet.Value][Skill] ~= nil then
									ChargeAnim = ChargeAnimations[AI.Settings.WeaponSkillSet.Value][Skill][1]
									ReleaseAnim = ChargeAnimations[AI.Settings.WeaponSkillSet.Value][Skill][2]
									TimeCharging = (math.random(10,20)/10)
								end
								if ChargeAnim ~= nil then
									Gyro("Create",nil,true,target)
									local SpecialSkill = {}
									local AN = LoadedAnimations[ChargeAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ChargeAnim)
									end
									AN:Play()
									AN.KeyframeReached:Connect(function(Frame)
										if Frame == "Freeze" then
											AN:AdjustSpeed(0)
										end
									end)
									task.wait(TimeCharging)
									AN:Stop()
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									local AN = LoadedAnimations[ReleaseAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ReleaseAnim)
									end
									AN:Play()
									task.wait(1)
									Gyro("Stop")
									SkillCooldown = false
								else
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									SkillCooldown = false
								end
								if table.find(Bosses,AI.Name) == nil then
									task.wait(math.random(12,15))
								else
									task.wait(math.random(5,10))
								end
								Rolled = false
							end
						end)()
						-- End Skills --

						if (AI:FindFirstChild("HumanoidRootPart").Position - target.Position).Magnitude <= 10 and AI:FindFirstChild("Stunned") == nil then
							coroutine.wrap(function()
								if CombatChill == false and SkillCooldown == false then
									CombatChill = true
									if CurrentString > 0 then
										Tick2 = tick()
										if math.abs(Tick1-Tick2) > 1.25 then
											CurrentString = 0
										end
									end
									Tick1 = tick()
									if CurrentString == 0 or CurrentString == 1 or CurrentString == 2 or CurrentString == 3 then
										CurrentString += 1
										local Anim = LoadedAnimations[AnimFolder:FindFirstChild(CurrentString)]
										if Anim == nil then
											Anim = AI.Humanoid.Animator:LoadAnimation(AnimFolder:FindFirstChild(CurrentString))
										end
										Anim:Play()
										Anim.KeyframeReached:Connect(function(Frame)
											if Frame == "Damage" then
												if AI:FindFirstChild("Stunned") ~= nil or HMD.Health <= 0 then return end
												game.ServerScriptService:FindFirstChild("BindableEvents"):FindFirstChild("Combat"):Fire(AI)
											end
										end)
										wait(Anim.Length+0.25)
										CombatChill = false
									else
										if CurrentString == 4 then
											CurrentString += 1
											local Anim = LoadedAnimations[AnimFolder:FindFirstChild(CurrentString)]
											if Anim == nil then
												Anim = AI.Humanoid.Animator:LoadAnimation(AnimFolder:FindFirstChild(CurrentString))
											end
											Anim:Play()
											Anim.KeyframeReached:Connect(function(Frame)
												if Frame == "Damage" then
													if AI:FindFirstChild("Stunned") ~= nil or HMD.Health <= 0 then return end
													game.ServerScriptService:FindFirstChild("BindableEvents"):FindFirstChild("Combat"):Fire(AI)
												end
											end)
											wait(Anim.Length + 2.5)
											CurrentString = 0
											CombatChill = false
										end
									end
								end
							end)()
						end
					else
						AI.Humanoid:MoveTo(AI.HumanoidRootPart.Position, AI)
					end
				end
			end
			wait() until script == nil
	end)()
	
	return ObjectsTable
end

return NPC
1 Like

Before I can even help (this code is messy), could you put the code into a code block using three `?

This is the Server Script:


```wait(5)

local NPC_OOP = require(game.ServerScriptService:FindFirstChild("NPCOOP_Handler"))

local SeaLevel = 130

local function KeepTrack(NPC,Point,Range)
	coroutine.wrap(function()
		local I = Instance.new("ObjectValue")
		I.Name = "SpawnPoint"
		I.Value = Point
		I.Parent = NPC
		local I = Instance.new("NumberValue")
		I.Name = "NPCRange"
		I.Value = Range or 75
		I.Parent = NPC
	end)()
end

local Bosses = {"RedHair","AxeHandMan","LightMan","MagmaMan","IceMan","BlackLeg","BanditLeader","LightningMan","SmokeMan","WhiteStache","DarkBeard","DoughMan","SandMan","CatCaptain","ClownCaptain","AmazonQueen","OneSwordMaster","TwoSwordMasterPrisoner","PWLightMan","SharkMan","RokushikiMasterMarine","GravityMan","ThreeSwordMan"}

for i,v in pairs(game.ReplicatedStorage.NPCS:GetChildren()) do
	for i,c in pairs(game.Workspace:FindFirstChild("NPCSpawns"):GetChildren()) do
		if c.Name == v.Name.."Spawn" then
			local AI = v:Clone()
			AI.HumanoidRootPart.Position = c.Position
			if table.find(Bosses,AI.Name) == nil then
				KeepTrack(AI,c)
			else
				KeepTrack(AI,c,250)
			end
			AI.Parent = game.Workspace
			local BG = Instance.new("BodyGyro")
			BG.MaxTorque = Vector3.new(math.huge,0,math.huge)
			BG.Parent = AI.HumanoidRootPart
			--game.ServerScriptService:FindFirstChild("BindableEvents"):FindFirstChild("NPCSetup"):Fire(AI, AI.Humanoid)
			NPC_OOP.new(AI)
		end
	end
end

game:GetService("Debris"):AddItem(script,5)

I’m not sure why the first portion won’t post like code.
I’m new to dev forum posting.

It’s probably because the ``` has to be on a separate line to function. Now, what exactly is the issue? Is the NPC not spawning, not moving, or any other specifics? That will help shorten the range of where we need to look for any issues in the code.

The NPC successfully spawns. The .Died() function doesn’t work, and it also doesn’t move.

Alright, I’m going to shorten the range of the code in this post, so you can probably ignore it.

function NPC.new(NPCObj,PointCheck,RangeCheck,Respawned)
	local ObjectsTable = {}
	

	local AI = NPCObj
	local HMD = AI:WaitForChild("Humanoid")
	
	AI.ChildAdded:Connect(function(Item)
		if Item:IsA("Model") and Item:FindFirstChild("WeaponName") then
			NPC.Haki(Item,AI)
		end
	end)

		local function KeepTrack(Point,Range)
			coroutine.wrap(function()
				local I = Instance.new("ObjectValue")
				I.Name = "SpawnPoint"
				I.Value = Point
				I.Parent = AI
				local I = Instance.new("NumberValue")
				I.Name = "NPCRange"
				I.Value = Range or 75
				I.Parent = AI
			end)()
		end

		local CF = AI.HumanoidRootPart.CFrame
		local AISettings = AI:FindFirstChild("Settings")
		AI:FindFirstChild("Humanoid").MaxHealth = 50 + (AISettings:FindFirstChild("Defense").Value*5)
		AI:FindFirstChild("Humanoid").Health = AI:FindFirstChild("Humanoid").MaxHealth
		--AI:FindFirstChild("Follow").Disabled = false

		if PointCheck ~= nil and RangeCheck ~= nil and Respawned == true then
			KeepTrack(PointCheck,RangeCheck)
		end

		if table.find(Announce,AI.Name) then
			for i,Player in pairs(game.Players:GetChildren()) do
				local Notif = game.ReplicatedStorage.UI:FindFirstChild("Notif"):Clone()
				Notif.Text = "SYSTEM: "..AI.Name.." Has Spawned!"
				Notif.TextColor3 = Color3.new(1, 1, 1)
				Notif:FindFirstChild("UIGradient"):FindFirstChild("Legendary").Disabled = false
				Notif.Parent = Player.PlayerGui:WaitForChild("Main"):WaitForChild("Notifications")
			end
		end

		local Idle = AI:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(game.ReplicatedStorage.Animations.Idle)
		Idle:Play()

		coroutine.wrap(function()
			local Range = AI:WaitForChild("NPCRange").Value
			local Point = AI:WaitForChild("SpawnPoint").Value
			local SeaLevel = 130
			game:GetService("RunService").Stepped:Connect(function()
				pcall(function()
					local RangeCheck = Range or 75
					if AI:FindFirstChild("Torso") then
						local HRP = AI:FindFirstChild("Torso")
						if (HRP.Position-Point.Position).Magnitude > RangeCheck or HRP.CFrame.Y <= SeaLevel then
							HRP.CFrame = Point.CFrame
						end
					end
				end)
			end)
		end)()

		local LoadThese = {}
		for i,v in pairs(game.ReplicatedStorage:GetDescendants()) do
			if v:IsA("Animation") then
				table.insert(LoadThese,v)
			end
		end
		for i,v in pairs(LoadThese) do
			AI:FindFirstChild("Humanoid"):LoadAnimation(v)
		end

		local RunAnim



		local AIClone = AI:Clone()
		HMD.Died:connect(function()
			AI.Head:FindFirstChild("Overhead"):Destroy()
			AI.Parent = game.Lighting
			game.ServerScriptService:FindFirstChild("BindableEvents"):FindFirstChild("DeathEffect"):Fire(AI)
			wait(AISettings:FindFirstChild("RespawnTime").Value)
			if Bosses[AI.Name] then
				if game.Workspace:FindFirstChild(AI.Name) == nil then
					AIClone:MakeJoints()
					AIClone.Parent = workspace
					AIClone.HumanoidRootPart.CFrame = CF
					Logic.SpawnNPC(AIClone.Name)
					AI:Destroy()
				else
					AI:Destroy()
				end
			else
				AIClone:MakeJoints()
				AIClone.Parent = workspace
			AIClone.HumanoidRootPart.CFrame = CF
			local NPC_OOP = require(game.ServerScriptService:FindFirstChild("NPCOOP_Handler"))
			NPC_OOP.new(AI)
				AI:Destroy()
			end
		end)

		AI:FindFirstChild("Humanoid").Running:Connect(function(Speed)
			if Speed >= 3 then
				RunAnim = AI:FindFirstChild("Humanoid").Animator:LoadAnimation(game.ReplicatedStorage:FindFirstChild("Animations"):FindFirstChild("Walk"))
				RunAnim:Play()
			else
				if RunAnim then
					RunAnim:Stop()
				end
			end
		end)

		if AISettings:FindFirstChild("HakiOn").Value == true then
			local HL = AISettings:FindFirstChild("HakiLevel").Value
			local LegArmament = false
			if AISettings:FindFirstChild("FightStyle").Value == "BlackLeg" then
				LegArmament = true
			end
			local ACR = AI:FindFirstChild("HakiColor"):FindFirstChild("R")
			local ACG = AI:FindFirstChild("HakiColor"):FindFirstChild("G")
			local ACB = AI:FindFirstChild("HakiColor"):FindFirstChild("B")
			local W1
			local W2
			if LegArmament == false then
				W1 = "Right Arm"
			else
				W1 = "Right Leg"
			end
			if LegArmament == false then
				W2 = "Left Arm"
			else
				W2 = "Left Leg"
			end
			local S = game.ReplicatedStorage:FindFirstChild("Sounds"):FindFirstChild("Armament"):Clone()
			S.Parent = AI.HumanoidRootPart
			S:Play()
			game.Debris:AddItem(S,S.TimeLength)
			local RA
			local LA
			local ML
			if AI:WaitForChild("Settings"):FindFirstChild("MissingLimb").Value == true then
				ML = AI:WaitForChild("Settings"):FindFirstChild("Limb").Value
			end
			if HL == 1 then
				RA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV1"):Clone()
				LA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV1"):Clone()
			elseif HL == 2 then
				RA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV2"):Clone()
				LA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV2"):Clone()
			elseif HL == 3 then
				RA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV3"):Clone()
				LA = game.ReplicatedStorage:FindFirstChild("Armament"):FindFirstChild("HakiV3"):Clone()
			end
			if ML then
				if ML == "Right Arm" then
					RA:FindFirstChild("HakiPart").Transparency = 1
				elseif ML == "Left Arm" then
					LA:FindFirstChild("HakiPart").Transparency = 1
				end
			end
			if AISettings.HasRyou.Value == "Has" or AISettings.HasRyou.Value == true then
				local I = Instance.new("StringValue")
				I.Name = "RyouHaki"
				I.Parent = AI
				if ML ~= "Right Arm" then
					for i,v in pairs(game.ServerScriptService:FindFirstChild("Ryou_Particles"):GetChildren()) do
						local X = v:Clone()
						if X.Name == "RyouMain" then
							X.Color = ColorSequence.new(Color3.fromRGB(ACR.Value,ACG.Value,ACB.Value))
						end
						X.Parent = RA:FindFirstChild("HakiPart")
						X.Enabled = true
					end
				end
				if ML ~= "Left Arm" then
					for i,v in pairs(game.ServerScriptService:FindFirstChild("Ryou_Particles"):GetChildren()) do
						local X = v:Clone()
						if X.Name == "RyouMain" then
							X.Color = ColorSequence.new(Color3.fromRGB(ACR.Value,ACG.Value,ACB.Value))
						end
						X.Parent = LA:FindFirstChild("HakiPart")
						X.Enabled = true
					end
				end
			end
			RA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").OutlineTransparency = 1
			RA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").FillTransparency = 1
			LA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").OutlineTransparency = 1
			LA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").FillTransparency = 1
			local TI = TweenInfo.new(0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
			local Goal = {FillTransparency = 0, OutlineTransparency = 0}
			local Animation = TS:Create(RA:FindFirstChild("HakiPart"):FindFirstChild("Highlight"), TI, Goal)
			Animation:Play()
			local TI = TweenInfo.new(0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
			local Goal = {FillTransparency = 0, OutlineTransparency = 0}
			local Animation = TS:Create(LA:FindFirstChild("HakiPart"):FindFirstChild("Highlight"), TI, Goal)
			Animation:Play()
			local w = Instance.new("Weld",AI:FindFirstChild(W1))
			w.Name = "ArmamentWeld"
			w.Part0 = AI:FindFirstChild(W1)
			w.Part1 = RA:FindFirstChild("Weld")
			w.C1 = CFrame.new(0,0,0)
			RA:FindFirstChild("Weld").Anchored = false
			RA.Name = "Armament"
			RA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").OutlineColor = Color3.fromRGB(ACR.Value,ACG.Value,ACB.Value)
			RA.Parent = AI
			local w = Instance.new("Weld",AI:FindFirstChild(W2))
			w.Name = "ArmamentWeld"
			w.Part0 = AI:FindFirstChild(W2)
			w.Part1 = LA:FindFirstChild("Weld")
			w.C1 = CFrame.new(0,0,0)
			LA:FindFirstChild("Weld").Anchored = false
			LA.Name = "Armament"
			LA:FindFirstChild("HakiPart"):FindFirstChild("Highlight").OutlineColor = Color3.fromRGB(ACR.Value,ACG.Value,ACB.Value)
			LA.Parent = AI
			local I = Instance.new("StringValue")
			I.Name = "ArmamentOn"
			I.Parent = AI
			local L = Instance.new("PointLight")
			L.Range = 12
			L.Brightness = 2
			L.Color = Color3.new(1, 0.333333, 0)
			L.Parent = AI.HumanoidRootPart
			local TI = TweenInfo.new(0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
			local Goal = {Range = 0,Brightness = 0}
			local Animation = TS:Create(L, TI, Goal)
			Animation:Play()
			game.Debris:AddItem(L,0.75)
		end

		local RaceModelNPC = {"Skypiean","Mink"}

		if table.find(RaceModelNPC,AISettings:FindFirstChild("Race").Value) then
			local RaceStuff = game.ReplicatedStorage:FindFirstChild("Race_Configurations"):FindFirstChild("RaceModels"):FindFirstChild(AISettings:FindFirstChild("Race").Value):Clone()
			for i,v in pairs(RaceStuff:GetChildren()) do
				if AI:FindFirstChild(v.Name) then
					local Wep = v
					for i,c in pairs(Wep:GetChildren()) do
						if c.Name == "Weld" then
							local w = Instance.new("Motor6D",AI:FindFirstChild(v.Name))
							w.Part0 = AI:FindFirstChild(v.Name)
							w.Part1 = Wep:FindFirstChild("Weld")
							w.C1 = CFrame.new(0,0,0)
							for i,v in pairs(Wep:GetChildren()) do
								if v:IsA("BasePart") then
									v.Anchored = false
								end
							end
						end
					end
				end
			end
			RaceStuff.Parent = AI
		end

		if AISettings:FindFirstChild("WeaponSlot").Value ~= "" then
			local Weapon = game.ReplicatedStorage.Weapons:FindFirstChild(AISettings:FindFirstChild("WeaponSlot").Value):Clone()
			local WN = Weapon.Name
			Weapon.Name = "Weapon"
			if Weapon:FindFirstChild("MultiWeld") == nil then
				local w = Instance.new("Motor6D",AI:FindFirstChild("Right Arm"))
				w.Part0 = AI:FindFirstChild("Right Arm")
				w.Part1 = Weapon:FindFirstChild("Weld")
				w.C1 = CFrame.new(0,0,0)
				for i,v in pairs(Weapon:GetChildren()) do
					if v:IsA("BasePart") then
						v.Anchored = false
					end
				end
				Weapon:FindFirstChild("Weld").Anchored = false
			else
				for i,v in pairs(Weapon:GetChildren()) do
					if AI:FindFirstChild(v.Name) then
						local Wep = v
						for i,c in pairs(Wep:GetChildren()) do
							if c.Name == "Weld" then
								local w = Instance.new("Motor6D",AI:FindFirstChild(v.Name))
								w.Part0 = AI:FindFirstChild(v.Name)
								w.Part1 = Wep:FindFirstChild("Weld")
								w.C1 = CFrame.new(0,0,0)
								for i,v in pairs(Wep:GetChildren()) do
									if v:IsA("BasePart") then
										v.Anchored = false
									end
								end
							end
						end
					end
				end
			end
			Weapon.Parent = AI
			--for i,haki in pairs(Weapon:GetDescendants()) do
			--	if haki:IsA("Script") then
			--		if haki.Name == "Haki" or haki.Name == "MultiHaki" then
			--			if AISettings:FindFirstChild("HakiOn").Value == true then
			--				haki.Disabled = false
			--			end
			--		end
			--	end
			--end
			if game.ReplicatedStorage:FindFirstChild("IdleAnimations"):FindFirstChild(AISettings:FindFirstChild("WeaponSlot").Value) ~= nil then
				local Idle = game.ReplicatedStorage:FindFirstChild("IdleAnimations"):FindFirstChild(AISettings:FindFirstChild("WeaponSlot").Value):FindFirstChild("Idle")
				local AN = AI:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(Idle)
				AN:Play()
			end
			AI:FindFirstChild("HumanoidRootPart").Anchored = false
		end

		local Acceptable = {66214495,204471960,73293890}

		AI:FindFirstChild("Humanoid").Died:Connect(function()
			for i,v in pairs(AI:FindFirstChild("EXPShare"):GetChildren()) do
				if game.Players:FindFirstChild(v.Name) then
					if v.Value >= (AI.Humanoid.MaxHealth/4) then
						local PTR = game.Players:FindFirstChild(v.Name)
						if table.find(Bosses,AI.Name) or table.find(AlsoRewardable,AI.Name) then
							if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(PTR.userId, 76813613) then
								rewards.Spin(AI.Name.."Double",1000,PTR)
							else
								rewards.Spin(AI.Name,1000,PTR)
							end
						end
						if game.ServerScriptService:FindFirstChild("EXP_Rates"):FindFirstChild(AI.Name) then
							local Rate = game.ServerScriptService:FindFirstChild("EXP_Rates"):FindFirstChild(AI.Name).Value
							if PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("Level").Value < game.ServerStorage.Caps:FindFirstChild("Level").Value then
								PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("EXP").Value += Rate
							else
								if table.find(Acceptable,PTR.UserId) then
									PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("EXP").Value += Rate
								end
							end
						end
						if game.ServerScriptService:FindFirstChild("Gold_Rates"):FindFirstChild(AI.Name) then
							local Rate
							if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(PTR.userId, 76813457) then
								Rate = (game.ServerScriptService:FindFirstChild("Gold_Rates"):FindFirstChild(AI.Name).Value*2)
							else
								Rate = game.ServerScriptService:FindFirstChild("Gold_Rates"):FindFirstChild(AI.Name).Value
							end
							if PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("Gold").Value + Rate <= game.ServerStorage.Caps:FindFirstChild("Gold").Value then
								PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("Gold").Value += Rate
							else
								if table.find(Acceptable,PTR.UserId) then
									PTR:WaitForChild("Stats"):WaitForChild("General"):WaitForChild("Gold").Value += Rate
								end
							end
						end
						if PTR:FindFirstChild("Quest") then
							local QF = PTR:FindFirstChild("Quest")
							if QF:FindFirstChild("Enemy").Value == AI.Name then
								QF:FindFirstChild("Defeated").Value += 1
							end
						end
					end
				end
			end
		end)

		for i,Hair in pairs(AI:GetDescendants()) do
			if Hair:IsA("BasePart") and Hair.Name == "Hair" then
				Hair.BrickColor = BrickColor.Random()
			end
		end

		local Skins = {}
		local SkinChoices = AI:FindFirstChild("Settings"):FindFirstChild("Skins"):FindFirstChild(AI:FindFirstChild("Settings"):FindFirstChild("Race").Value)
		for i,v in pairs(SkinChoices:GetChildren()) do
			table.insert(Skins,v)
		end
		local NOS = table.getn(Skins)
		local Rando = math.random(1,NOS)
		local ChosenSkin = Skins[Rando]

		for i,v in pairs(AI:GetChildren()) do
			if v.Name == "Head" or v.Name == "Torso" or v.Name == "Right Arm" or v.Name == "Right Leg" or v.Name == "Left Arm" or v.Name == "Left Leg" or v.Name == "Fin" then
				v.BrickColor = ChosenSkin.Value
			end
	end
	
	local HMD = AI:FindFirstChild("Humanoid")
	
	local larm = AI:FindFirstChild("Left Arm")
	local rarm = AI:FindFirstChild("Right Arm")
	local Folder = AI:FindFirstChild("Settings")
	local CS = game:GetService("CollectionService")
	local CF = AI.HumanoidRootPart.CFrame
	local OriginalSpeed = tonumber(AI.Humanoid.WalkSpeed)

	local LoadedAnimations = {}

	local SkillCooldown = false
	local TPCooldown = false
	local GlobalCooldown = false
	local Rolled = false

	local CombatChill = false
	local Tick1,Tick2
	local CurrentString = 0
	local AM = AI:FindFirstChild("Humanoid")
	local AnimFolder
	if Folder:FindFirstChild("WeaponSlot").Value == "" then
		AnimFolder = game.ReplicatedStorage:FindFirstChild("FightStyleAnimations"):FindFirstChild(Folder:FindFirstChild("FightStyle").Value)
	else
		AnimFolder = game.ReplicatedStorage:FindFirstChild("WeaponAnimations"):FindFirstChild(Folder:FindFirstChild("WeaponSlot").Value)
	end
	local LoopOn = false
	coroutine.wrap(function()
		repeat
			if AI:FindFirstChild("Stunned") == nil and SkillCooldown == false and AI:FindFirstChild("Staggered") == nil and CS:HasTag(AI,"Blocking") == false and CS:HasTag(AI,"UsingSkill") == false and HMD.Health > 0 then
				if #game.Players:GetPlayers() > 0 then

					local dist
					local Nearest = {}

					for i,v in pairs(game.Players:GetChildren()) do
						if v ~= nil and v.Character ~= nil then
							local CharDist = table.create(1,v.Name)
							pcall(function()	
								CharDist[2] = (v.Character.HumanoidRootPart.Position - AI.HumanoidRootPart.Position).Magnitude
								table.insert(Nearest,CharDist)
							end)
						end
					end

					if table.getn(Nearest) > 1 then
						table.sort(Nearest, 
							function(a,b)
								return tonumber(a[2])<tonumber(b[2])
							end
						)
					end

					local targettorso
					local target

					if Nearest ~= nil and Nearest[1] ~= nil and Nearest[1][1] ~= nil then -- Fixed Error by having it check Nearest[1][1] is not nil before firing below if statement no more errors
						if game.Players:FindFirstChild(Nearest[1][1]) ~= nil then -- Line Erroring due to Nil when its looking for a number.
							targettorso = game.Players:FindFirstChild(Nearest[1][1])
						else
							targettorso = nil
						end
					end
					if targettorso ~= nil then
						target = targettorso.Character:FindFirstChild("Torso")
					else
						target = nil
					end
					if HMD.Health < HMD.MaxHealth then
						local CustomDistance = {RedHair = 200,CorruptSwordsman = 200,MagmaMan = 250,LightMan = 250,IceMan = 250,DarkBeard = 250,DoughMan = 250}
						if Bosses[AI.Name] then
							dist = CustomDistance[AI.Name]
						else
							dist = 75	
							print(dist)
						end

						if AI:FindFirstChild("UsingObservation") == nil and AI:FindFirstChild("Settings"):FindFirstChild("Observation").Value == true then
							local I = Instance.new("StringValue")
							I.Name = "UsingObservation"
							I.Parent = AI

						end
					else
						dist = 0
					end
					if target ~= nil and (AI:FindFirstChild("HumanoidRootPart").Position - target.Position).Magnitude <= dist then
						AI.Humanoid:MoveTo(target.Position, target)

						-- Skills
						coroutine.wrap(function()
							if NPCSkillSets[AI.Settings.Core.Value] ~= nil and Rolled == false and SkillCooldown == false and AI.Settings.PrimarySkillSet.Value == "Core" then
								Rolled = true
								SkillCooldown = true
								local SkillOptions = table.getn(NPCSkillSets[AI.Settings.Core.Value])
								local Choose = math.random(1,SkillOptions)
								local Skill = NPCSkillSets[AI.Settings.Core.Value][Choose]
								local ChargeAnim
								local ReleaseAnim
								local TimeCharging
								if ChargeAnimations[AI.Settings.Core.Value][Skill] ~= nil then
									ChargeAnim = ChargeAnimations[AI.Settings.Core.Value][Skill][1]
									ReleaseAnim = ChargeAnimations[AI.Settings.Core.Value][Skill][2]
									TimeCharging = (math.random(10,20)/10)
								end
								if ChargeAnim ~= nil then
									Gyro("Create",nil,true,target)
									local SpecialSkill = {}
									if tostring(Skill) == "FireConqueror" or tostring(Skill) == "BlackHole" or tostring(Skill) == "IceSpear" or tostring(Skill) == "MochiSlam" or tostring(Skill) == "MochiHotShot" or tostring(Skill) == "ThunderBomb" then
										if tostring(Skill) == "MochiSlam" then
											Logic.CreateSkillEffects(AI,"MochiArm")
										elseif tostring(Skill) == "MochiHotShot" then
											Logic.CreateSkillEffects(AI,"MochiArmHot")
										else
											Logic.CreateSkillEffects(AI,tostring(Skill))
										end
									end
									local AN = LoadedAnimations[ChargeAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ChargeAnim)
									end
									AN:Play()
									AN.KeyframeReached:Connect(function(Frame)
										if Frame == "Freeze" then
											AN:AdjustSpeed(0)
										end
									end)
									task.wait(TimeCharging)
									AN:Stop()
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									local AN = LoadedAnimations[ReleaseAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ReleaseAnim)
									end
									AN:Play()
									task.wait(1)
									Gyro("Stop")
									SkillCooldown = false
								else
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									SkillCooldown = false
								end
								if tostring(Skill) ~= "Barrier" and tostring(Skill) ~= "Invisible" then
									task.wait(math.random(8,10))
								else
									if table.find(Bosses,AI.Name) == nil then
										task.wait(math.random(12,15))
									else
										task.wait(math.random(5,10))
									end
								end
								Rolled = false
							end
							if CombatSkillSets[AI.Settings.CombatSkillSet.Value] ~= nil and Rolled == false and SkillCooldown == false and AI.Settings.PrimarySkillSet.Value == "Combat" then
								Rolled = true
								SkillCooldown = true
								local SkillOptions = table.getn(CombatSkillSets[AI.Settings.CombatSkillSet.Value])
								local Choose = math.random(1,SkillOptions)
								local Skill = CombatSkillSets[AI.Settings.CombatSkillSet.Value][Choose]
								local ChargeAnim
								local ReleaseAnim
								local TimeCharging
								if ChargeAnimations[AI.Settings.CombatSkillSet.Value][Skill] ~= nil then
									ChargeAnim = ChargeAnimations[AI.Settings.CombatSkillSet.Value][Skill][1]
									ReleaseAnim = ChargeAnimations[AI.Settings.CombatSkillSet.Value][Skill][2]
									TimeCharging = (math.random(10,20)/10)
								end
								if ChargeAnim ~= nil then
									Gyro("Create",nil,true,target)
									local SpecialSkill = {}
									local AN = LoadedAnimations[ChargeAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ChargeAnim)
									end
									AN:Play()
									AN.KeyframeReached:Connect(function(Frame)
										if Frame == "Freeze" then
											AN:AdjustSpeed(0)
										end
									end)
									task.wait(TimeCharging)
									AN:Stop()
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									local AN = LoadedAnimations[ReleaseAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ReleaseAnim)
									end
									AN:Play()
									task.wait(1)
									Gyro("Stop")
									SkillCooldown = false
								else
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									SkillCooldown = false
								end
								if table.find(Bosses,AI.Name) == nil then
									task.wait(math.random(12,15))
								else
									task.wait(math.random(5,10))
								end
								Rolled = false
							end
							if SwordSkillSets[AI.Settings.WeaponSkillSet.Value] ~= nil and Rolled == false and SkillCooldown == false and AI.Settings.PrimarySkillSet.Value == "Weapon" then
								Rolled = true
								SkillCooldown = true
								local SkillOptions = table.getn(SwordSkillSets[AI.Settings.WeaponSkillSet.Value])
								local Choose = math.random(1,SkillOptions)
								local Skill = SwordSkillSets[AI.Settings.WeaponSkillSet.Value][Choose]
								local ChargeAnim
								local ReleaseAnim
								local TimeCharging
								if ChargeAnimations[AI.Settings.WeaponSkillSet.Value][Skill] ~= nil then
									ChargeAnim = ChargeAnimations[AI.Settings.WeaponSkillSet.Value][Skill][1]
									ReleaseAnim = ChargeAnimations[AI.Settings.WeaponSkillSet.Value][Skill][2]
									TimeCharging = (math.random(10,20)/10)
								end
								if ChargeAnim ~= nil then
									Gyro("Create",nil,true,target)
									local SpecialSkill = {}
									local AN = LoadedAnimations[ChargeAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ChargeAnim)
									end
									AN:Play()
									AN.KeyframeReached:Connect(function(Frame)
										if Frame == "Freeze" then
											AN:AdjustSpeed(0)
										end
									end)
									task.wait(TimeCharging)
									AN:Stop()
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									local AN = LoadedAnimations[ReleaseAnim]
									if AN == nil then
										AN = AI.Humanoid.Animator:LoadAnimation(ReleaseAnim)
									end
									AN:Play()
									task.wait(1)
									Gyro("Stop")
									SkillCooldown = false
								else
									game.ServerScriptService.BindableEvents.Skills:Fire(AI, Skill, target.CFrame)
									SkillCooldown = false
								end
								if table.find(Bosses,AI.Name) == nil then
									task.wait(math.random(12,15))
								else
									task.wait(math.random(5,10))
								end
								Rolled = false
							end
						end)()
						-- End Skills --

						if (AI:FindFirstChild("HumanoidRootPart").Position - target.Position).Magnitude <= 10 and AI:FindFirstChild("Stunned") == nil then
							coroutine.wrap(function()
								if CombatChill == false and SkillCooldown == false then
									CombatChill = true
									if CurrentString > 0 then
										Tick2 = tick()
										if math.abs(Tick1-Tick2) > 1.25 then
											CurrentString = 0
										end
									end
									Tick1 = tick()
									if CurrentString == 0 or CurrentString == 1 or CurrentString == 2 or CurrentString == 3 then
										CurrentString += 1
										local Anim = LoadedAnimations[AnimFolder:FindFirstChild(CurrentString)]
										if Anim == nil then
											Anim = AI.Humanoid.Animator:LoadAnimation(AnimFolder:FindFirstChild(CurrentString))
										end
										Anim:Play()
										Anim.KeyframeReached:Connect(function(Frame)
											if Frame == "Damage" then
												if AI:FindFirstChild("Stunned") ~= nil or HMD.Health <= 0 then return end
												game.ServerScriptService:FindFirstChild("BindableEvents"):FindFirstChild("Combat"):Fire(AI)
											end
										end)
										wait(Anim.Length+0.25)
										CombatChill = false
									else
										if CurrentString == 4 then
											CurrentString += 1
											local Anim = LoadedAnimations[AnimFolder:FindFirstChild(CurrentString)]
											if Anim == nil then
												Anim = AI.Humanoid.Animator:LoadAnimation(AnimFolder:FindFirstChild(CurrentString))
											end
											Anim:Play()
											Anim.KeyframeReached:Connect(function(Frame)
												if Frame == "Damage" then
													if AI:FindFirstChild("Stunned") ~= nil or HMD.Health <= 0 then return end
													game.ServerScriptService:FindFirstChild("BindableEvents"):FindFirstChild("Combat"):Fire(AI)
												end
											end)
											wait(Anim.Length + 2.5)
											CurrentString = 0
											CombatChill = false
										end
									end
								end
							end)()
						end
					else
						AI.Humanoid:MoveTo(AI.HumanoidRootPart.Position, AI)
					end
				end
			end
			wait() until script == nil
	end)()
	
	return ObjectsTable
end

and

for i,v in pairs(game.ReplicatedStorage.NPCS:GetChildren()) do
	for i,c in pairs(game.Workspace:FindFirstChild("NPCSpawns"):GetChildren()) do
		if c.Name == v.Name.."Spawn" then
			local AI = v:Clone()
			AI.HumanoidRootPart.Position = c.Position
			if table.find(Bosses,AI.Name) == nil then
				KeepTrack(AI,c)
			else
				KeepTrack(AI,c,250)
			end
			AI.Parent = game.Workspace
			local BG = Instance.new("BodyGyro")
			BG.MaxTorque = Vector3.new(math.huge,0,math.huge)
			BG.Parent = AI.HumanoidRootPart
			--game.ServerScriptService:FindFirstChild("BindableEvents"):FindFirstChild("NPCSetup"):Fire(AI, AI.Humanoid)
			NPC_OOP.new(AI)
		end
	end
end

There could be a couple of problems here. One, you are doing NPC_OOP on the dead AI and not the new one. In the same section, AIClone’s parent would be workspace already since you set the parent here

then make the AI of it. So, you would need to set the AIClone’s parent to somewhere else like ServerStorage. Fix:

		local AIClone = AI:Clone()
		AIClone.Parent = game.ServerStorage
		HMD.Died:connect(function()
			AI.Head:FindFirstChild("Overhead"):Destroy()
			AI.Parent = game.Lighting
			game.ServerScriptService:FindFirstChild("BindableEvents"):FindFirstChild("DeathEffect"):Fire(AI)
			wait(AISettings:FindFirstChild("RespawnTime").Value)
			if Bosses[AI.Name] then
				if game.Workspace:FindFirstChild(AI.Name) == nil then
					AIClone:MakeJoints()
					AIClone.Parent = workspace
					AIClone.HumanoidRootPart.CFrame = CF
					Logic.SpawnNPC(AIClone.Name)
					AI:Destroy()
				else
					AI:Destroy()
				end
			else
				AIClone:MakeJoints()
				AIClone.Parent = workspace
				AIClone.HumanoidRootPart.CFrame = CF
				local NPC_OOP = require(game.ServerScriptService:FindFirstChild("NPCOOP_Handler"))
				NPC_OOP.new(AIClone)
				AI:Destroy()
			end
		end)

None of that seemed to work. The issue is that 1. The NPC Died function isn’t running at all. I did adjust running the OOP to the new NPC instead of the dead one. This made no difference. It’s almost as if the loop for the following stops working for some reason.

Could you elaborate on what your issue is? You aren’t really explaining what the issue is but the first thing I noticed is that you are never setting the metatable of your created objects and aren’t really using a typical OO layout. In order for the object to inherit class methods you need to set the metatable of your created objects to the table of class methods.

In Lua and other languages, OOP’s main advantage is its capability to lessen memory usage through inheritance but I noticed that you are creating many functions and threads for each object which is going to increase memory usage very quickly so I would highly suggest breaking up your constructor into multiple methods for each functionality that your NPC has. Generally a constructor should only be creating properties (incl. events) that need to exist per-object, functions should exist inside of your class table so every object of a single class shares the same single function, not inside of the object, and then in your constructor you would set the metatable of the created object to the class table to inherit the methods.