here is the script
local Ignorelist = workspace.D
for i, obj in pairs(Ignorelist:GetDescendants()) do-------Loop through descendants or children to set all parts to false in the ignore list
if obj and obj:IsA(“Model”) then
for i, obj in pairs(Ignorelist:GetDescendants()) do-------Loop through descendants or children to set all parts to false in the ignore list
if obj and obj:IsA(“Part”) then
obj.CanCollide = false
end
end
end
end
local Demon = script.Parent
local db = false
local humanoid = Demon.Humanoid
local humanoid2 = game.Workspace.Jumpscare.Body.AnimationController
local attack = Instance.new(“Animation”)
attack.AnimationId = “rbxassetid://13816995744”
Demon.PrimaryPart:SetNetworkOwner(nil)
local PathfindingService = game:GetService(“PathfindingService”)
local function canSeeTarget(target)
local origin = Demon.HumanoidRootPart.Position
local direction = (target.HumanoidRootPart.Position - Demon.HumanoidRootPart.Position).unit * 40
local ray = Ray.new(origin, direction)
local hit, pos = workspace:FindPartOnRay(ray, Demon)
if hit then
if hit:IsDescendantOf(target) then
return true
end
else
return false
end
end
local function findTarget()
local players = game.Players:GetPlayers()
local maxDistance = 70
local nearestTarget
for index, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (Demon.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance < maxDistance and canSeeTarget(target) then
nearestTarget = target
maxDistance = distance
end
end
end
return nearestTarget
end
local function getPath(destination)
local pathParams = {
["AgentHeight"] = 8.5,
["AgentRadius"] = 11,
["AgentCanJump"] = false
}
local path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(Demon.HumanoidRootPart.Position, destination.Position)
return path
end
local function attack(target)
local distance = (Demon.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance > 3 then
humanoid:MoveTo(target.HumanoidRootPart.Position)
else
db = true
local body = game.Workspace.Jumpscare.Body.Body
body[“Jumpscare sound effect”]:Play()
local playerDeath = game.ReplicatedStorage.Remotes:WaitForChild(“playerDeath”)
local player = game.Players:GetPlayerFromCharacter(target)
print(player)
print("d1")
print(player)
target.Humanoid.Health = 0
wait(4)
db = false
end
end
local function walkTo(destination)
local path = getPath(destination)
if path.Status == Enum.PathStatus.Success then
for index, waypoint in pairs(path:GetWaypoints()) do
local target = findTarget()
if target then
attack(target)
break
else
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
end
else
humanoid:MoveTo(destination.position - (Demon.HumanoidRootPart.CFrame.LookVector * 10))
end
end
local function Patrol()
local waypoints = workspace.waypoints:GetChildren()
local randomNum = math.random (1, #waypoints)
walkTo(waypoints[randomNum])
end
while wait(0) do
Patrol()
end