Let me know if this helps.
Thanks.
--Game Init
local Guard = require(game.ServerScriptService.Npc.Guard)
local GuardModel = game.ServerStorage:WaitForChild("Guard")
local Zombie = require(game.ServerScriptService.Npc.Zombie)
local ZombieModel = game.ServerStorage:WaitForChild("Zombie")
function main()
--Create Guard Model
local guardModel1 = GuardModel:Clone()
local rootPart = guardModel1:WaitForChild("HumanoidRootPart")
rootPart.CFrame = CFrame.new(-1, 0.5, -57)
--Add guardModel1 to workspace
guardModel1.Parent = workspace
----Create Guard Module
local guard1 = Guard.new("-1, 0.5, -57" , 100, 2, 3, 5, "{'-1, 0.5, -57','-1, 0.5, -57'}")
--Create Zombie Model
local zombieModel1 = ZombieModel:Clone()
local rootPart = zombieModel1:WaitForChild("HumanoidRootPart")
rootPart.CFrame = CFrame.new(-25, 0.5, -57)
--Add zombieModel1 to workspace
zombieModel1.Parent = workspace
----Create Guard Module
local zombie1 = Zombie.new("-1, 0.5, -57" , 100, 2, 3, 5, "{'-1, 0.5, -57','-1, 0.5, -57'}")
end
main()
--Npc.BaseNpc
--Services
local PlayerService = game:GetService("Players")
BaseNpc = {}
BaseNpc.__index = BaseNpc
function BaseNpc.new(position, health, speed, visionDistance, hearingDistance)
local item = {}
setmetatable(item, BaseNpc)
item.Position = position
item.Health = health
item.Speed = speed
item.VisionDistance = visionDistance
item.HearingDistance = hearingDistance
return item
end
function BaseNpc:CheckForNearbyPlayers(npc)
local npcRootPart = npc:WaitForChild("HumanoidRootPart")
--TODO: Find player within vision distance and line of site
for _,player in pairs(game.Players:GetPlayers()) do
return player
end
return nil
end
return BaseNpc
--Npc.Guard
BaseNpc = require(game.ServerScriptService.Npc.BaseNpc)
Guard = {}
Guard.__index = Guard
setmetatable(Guard, BaseNpc)
function Guard.new(position, health, speed, visionDistance, hearingDistance, patrolVectors)
local item = BaseNpc.new(position, health, speed, visionDistance, hearingDistance)
setmetatable(item, Guard)
item.PatrolVectors = patrolVectors
return item
end
function Guard:Patrol()
print("Guard Patrol: "..self.PatrolVectors)
end
return Guard
--NpcZombie
BaseNpc = require(game.ServerScriptService.Npc.BaseNpc)
Zombie = {}
Zombie.__index = Zombie
setmetatable(Zombie, BaseNpc)
function Zombie.new(position, health, speed, visionDistance, hearingDistance)
local item = BaseNpc.new(position, health, speed, visionDistance, hearingDistance)
setmetatable(item, Zombie)
--item.Powerup = powerup
return item
end
function Zombie:Wander()
print("Zombie Wander")
end
return Zombie
--ServerStorage.Guard.Script
local guard = require(game.ServerScriptService.Npc.Guard)
--Declaring variables regarding this NPC/Model
local character = script.Parent
local humanoid = character.Humanoid
local rootPart = character.HumanoidRootPart
--[[
Main function of the NPC, commands the entire script.
It is to be inserted here any new functionalities that this NPC might get,
Such as smart pathfinding, attacking, etc..
For now, it just keeps telling the NPC to move.
]]--
local function main()
humanoid.WalkSpeed = 2 --Property on BaseNpc.Speed
local target = nil --Player target that is being chased
local previousTarget = nil --Player target that is being chased
local targetLastKnownPosition
repeat
wait()
--Look for Nearby Players until a Target is returned
--This logic is in the BaseNpc module
--Take some action if a target is found
--Guard Class Function: Patrol if not found
until humanoid.Health < 1 --loop until dead
end
main()