I need help with my boss as it doesn’t want to attack me or do anything. Its got a custom collision group but I don’t know if that affects anything…
SCRIPT:
local PathfindingService = game:GetService("PathfindingService")
local Debris = game:GetService("Debris")
local Infernal = script.Parent
local HRP = Infernal:WaitForChild("HumanoidRootPart")
local BodyPosition = HRP:WaitForChild("BodyPosition")
local Humanoid = Infernal:WaitForChild("Humanoid")
local Effects = workspace:WaitForChild("Effects")
BodyPosition.Position = HRP.Position + Vector3.new(0, script.Height.Value, 0) + Vector3.new(0, math.random(-1.5,1.5), 0)
local Waypoints = workspace:WaitForChild("BossWaypoints")
--[[
while true do
task.wait(1)
BodyPosition.Position = HRP.Position + Vector3.new(0, -5, 0)
task.wait(1)
BodyPosition.Position = HRP.Position + Vector3.new(0, 5, 0)
end
]]
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
rayParams.FilterDescendantsInstances = {Infernal}
local pathParams = {
AgentHeight = 5,
AgentRadius = 3,
AgentCanJump = true,
}
local lastPos
local RANGE = 999999999999999
local function PlaySound(ID, Volume)
local Sound = Instance.new("Sound", Effects)
Sound.Volume = Volume
Sound.SoundId = "rbxassetid://" .. ID
Sound.Loaded:Wait()
Sound:Play()
Debris:AddItem(Sound, Sound.TimeLength + 0.1)
end
local function canSeeTarget(target)
local orgin = HRP.Position
local direction = (target.HumanoidRootPart.Position - HRP.Position).Unit * RANGE
local ray = workspace:Raycast(orgin, direction, rayParams)
if ray and ray.Instance then
if ray.Instance:IsDescendantOf(target) then
return true
else
return false
end
else
return false
end
end
local function findTarget()
local players = game.Players:GetPlayers()
local maxDistance = RANGE
local nearestTarget
for i, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (HRP.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 path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(HRP.Position, destination.Position)
return path
end
local function Charge(target)
local distance = (HRP.Position - target.HumanoidRootPart.Position).Magnitude
local debounce = false
if distance > RANGE then
BodyPosition.Position = target.HumanoidRootPart.Position
PlaySound(7267837723, 1)
task.wait(2)
end
end
local function walkTo(destination)
local path = getPath(destination)
if path.Status == Enum.PathStatus.Success then
for i, waypoint in pairs(path:GetWaypoints()) do
path.Blocked:Connect(function()
path:Destroy()
end)
local target = findTarget()
if target and target.Humanoid.Health > 0 then
lastPos = target.HumanoidRootPart.Position
Charge(target)
break
else
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
if lastPos then
BodyPosition.Position = lastPos
task.wait(1)
lastPos = nil
break
else
BodyPosition.Position = waypoint.Position
task.wait(1)
end
end
end
else
return
end
end
local function patrol()
local waypoints = Waypoints:GetChildren()
local randomNum = math.random(1, #waypoints)
walkTo(waypoints[randomNum])
end
task.spawn(function()
while task.wait(0.2) do
patrol()
end
end)

