Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Setting
- local nametag = "KollowMC" --ForDeathCheck
- local Owner = workspace:WaitForChild(nametag) --ForSetting
- local amount = 12 --Amount of NPC
- local sideincreasement = 0 --Go to line 110 for setting
- local formationIncreasement = -4 --distance between each line
- local damage = 50
- local health = 400
- local speed = 30
- local meleedistance = 3
- local team = BrickColor.new("Grime")
- local attackowner = false
- local follow = true
- local attack = true
- wait(2)
- for I = 1,amount do
- local parts = Instance.new("Part")
- parts.Anchored = true
- parts.CanCollide = false
- local model = Instance.new("Model",workspace)
- model.Name = "NPC #"..math.random(100,3000)
- function OnMotorWeld(name,Primary,Secondary)
- local newmotor = Instance.new("Motor6D")
- newmotor.Name = name
- newmotor.Part0 = Primary
- newmotor.Part1 = Secondary
- newmotor.C1 = Secondary.CFrame:Inverse()
- newmotor.C0 = Primary.CFrame:Inverse()
- newmotor.Parent = Primary
- end
- --CharacterCreator--
- local bodycolor = Instance.new("BodyColors",model)
- bodycolor.HeadColor = BrickColor.new("Wheat")
- bodycolor.TorsoColor = BrickColor.new("Storm blue")
- bodycolor.LeftArmColor = BrickColor.new("Wheat")
- bodycolor.RightArmColor = BrickColor.new("Wheat")
- bodycolor.LeftLegColor = BrickColor.new("Black")
- bodycolor.RightLegColor = BrickColor.new("Black")
- local head = parts:Clone()
- head.Parent = model
- head.Name = "Head"
- head.Size = Vector3.new(2,1,1)
- head.Position = head.Position + Vector3.new(0.5,4.5,0)
- local specialmesh = Instance.new("SpecialMesh",head)
- specialmesh.Scale = Vector3.new(1.25,1.25,1.25)
- specialmesh.MeshType = Enum.MeshType.Head
- local torso = parts:Clone()
- torso.Parent = model
- torso.Name = "Torso"
- torso.Size = Vector3.new(2,2,1)
- torso.Position = torso.Position + Vector3.new(0.5,3,0)
- local Larm = parts:Clone()
- Larm.Parent = model
- Larm.Name = "Left Arm"
- Larm.Size = Vector3.new(1,2,1)
- Larm.Position = Larm.Position + Vector3.new(-1,3,0)
- local Rarm = parts:Clone()
- Rarm.Parent = model
- Rarm.Name = "Right Arm"
- Rarm.Size = Vector3.new(1,2,1)
- Rarm.Position = Rarm.Position + Vector3.new(2,3,0)
- local Lleg = parts:Clone()
- Lleg.Parent = model
- Lleg.Name = "Left Leg"
- Lleg.Size = Vector3.new(1,2,1)
- Lleg.Position = Lleg.Position + Vector3.new(0,1,0)
- local Rleg = parts:Clone()
- Rleg.Parent = model
- Rleg.Name = "Right Leg"
- Rleg.Size = Vector3.new(1,2,1)
- Rleg.Position = Rleg.Position + Vector3.new(1,1,0)
- local humanoidrootpart = parts:Clone()
- humanoidrootpart.Parent = model
- humanoidrootpart.Name = "HumanoidRootPart"
- humanoidrootpart.Size = Vector3.new(2,2,1)
- humanoidrootpart.Transparency = 1
- humanoidrootpart.Position = humanoidrootpart.Position + Vector3.new(0.5,3,0)
- model.PrimaryPart = humanoidrootpart
- local humanoid = Instance.new("Humanoid")
- humanoid.Parent = model
- humanoid.MaxHealth = health
- humanoid.Health = health
- humanoid.WalkSpeed = speed
- humanoid.Name = "Humanoid"
- local NPCteam = Instance.new("BrickColorValue",model)
- NPCteam.Value = team
- NPCteam.Name = "Team"
- --WeldingMotor6D--
- OnMotorWeld("RootJoint",humanoidrootpart,torso)
- OnMotorWeld("Right Hip",torso,Rleg)
- OnMotorWeld("Left Hip",torso,Lleg)
- OnMotorWeld("Left Shoulder",torso,Larm)
- OnMotorWeld("Right Shoulder",torso,Rarm)
- OnMotorWeld("Neck",torso,head)
- --AnchoredRemover--
- head.Anchored = false
- humanoidrootpart.Anchored = false
- torso.Anchored = false
- Larm.Anchored = false
- Rarm.Anchored = false
- Lleg.Anchored = false
- Rleg.Anchored = false
- --Function&Command--
- model:SetPrimaryPartCFrame(Owner.HumanoidRootPart.CFrame * CFrame.new(-10 + sideincreasement,0.5,formationIncreasement))
- if I % 5 ~= 0 then
- sideincreasement = sideincreasement + 5 --Distance between person
- else
- sideincreasement = 0
- formationIncreasement = formationIncreasement -4
- end
- --AIfunction
- local damagecooldown = false
- function OnAttack(hit)
- local ontarget = OnTarget()
- local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
- if hum and damagecooldown == false and ontarget == hum.Parent then
- damagecooldown = true
- hum:TakeDamage(damage)
- wait(1)
- damagecooldown = false
- end
- end
- Larm.Touched:Connect(OnAttack)
- Rarm.Touched:Connect(OnAttack)
- function OnTarget()
- local children = workspace:GetChildren()
- local target = nil
- local distance = 100
- for I = 1,#children do
- local currentchildren = children[I]
- if currentchildren.ClassName == "Model" and currentchildren ~= model then
- local humanoid = currentchildren:FindFirstChildOfClass("Humanoid")
- local rootpart = currentchildren:FindFirstChild("HumanoidRootPart") or currentchildren.PrimaryPart or currentchildren:FindFirstChild("Torso")
- local plrcheck = game.Players:GetPlayerFromCharacter(currentchildren)
- local enemyteam = currentchildren:FindFirstChild("Team")
- if rootpart and humanoid and (currentchildren ~= workspace:FindFirstChild(nametag) or (currentchildren == workspace:FindFirstChild(nametag) and attackowner == true)) then
- if plrcheck and enemyteam == nil then
- enemyteam = Instance.new("BrickColorValue")
- enemyteam.Value = plrcheck.TeamColor
- end
- if rootpart and humanoid and humanoid.Health > 0 and humanoid.Health < 99999999999 and ((enemyteam == nil or NPCteam == nil) or (NPCteam.Value == BrickColor.new("White") or (enemyteam.Value == BrickColor.new("White") or enemyteam.Value ~= NPCteam.Value))) then
- local targetdist = (rootpart.Position - humanoidrootpart.Position).magnitude
- if targetdist <= distance then
- target = currentchildren
- distance = targetdist
- end
- end
- end
- end
- end
- return target
- end
- spawn(function()
- while wait(0.2) do
- if humanoid.Health > 0 and workspace:FindFirstChild(nametag) and workspace:FindFirstChild(nametag):FindFirstChildOfClass("Humanoid") and workspace:FindFirstChild(nametag):FindFirstChildOfClass("Humanoid").Health > 0 then
- local Target = OnTarget()
- print(Target)
- if (Target and ((Target ~= workspace:FindFirstChild("KollowMC")) or (Target == workspace:FindFirstChild("KollowMC") and attackowner == true))) and attack == true then
- if (Target.PrimaryPart.Position - humanoidrootpart.Position).magnitude > 4 then
- humanoid:MoveTo(Target.HumanoidRootPart.Position)
- else
- humanoid:MoveTo(humanoidrootpart.Position)
- end
- else
- if follow == true and (humanoidrootpart.Position - workspace:FindFirstChild(nametag).HumanoidRootPart.Position).magnitude > 10 then
- humanoid:MoveTo(workspace:FindFirstChild(nametag).HumanoidRootPart.Position)
- else
- humanoid:MoveTo(humanoidrootpart.Position)
- end
- end
- else
- model:Remove()
- break
- end
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement