#Monster Ai Help
8 messages · Page 1 of 1 (latest)
no script no help
script local npc = script.Parent
local humanoidRootPart = npc:WaitForChild("HumanoidRootPart")
local bodyVelocity = humanoidRootPart:FindFirstChildOfClass("BodyVelocity") or Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(10000, 10000, 10000)
bodyVelocity.Parent = humanoidRootPart
local players = game:GetService("Players")
local ceilingHeight = 50
local floorHeight = 5
local detectionRange = 20
local fallSpeed = 50
local chaseSpeed = 30
local function fallToFloor()
bodyVelocity.Velocity = Vector3.new(0, -fallSpeed, 0)
end
local function chasePlayer(player)
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
local targetPosition = player.Character.HumanoidRootPart.Position
local direction = (targetPosition - humanoidRootPart.Position).unit
bodyVelocity.Velocity = direction * chaseSpeed
end
end
local function isPlayerInRange(player)
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
return (player.Character.HumanoidRootPart.Position - humanoidRootPart.Position).Magnitude < detectionRange
end
return false
end
while true do
local closestPlayer = nil
local closestDistance = math.huge
for _, player in ipairs(players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
local distance = (player.Character.HumanoidRootPart.Position - humanoidRootPart.Position).Magnitude
if distance < closestDistance then
closestPlayer = player
closestDistance = distance
end
end
end
Other half
if closestPlayer and isPlayerInRange(closestPlayer) then
if humanoidRootPart.Position.Y > floorHeight then
fallToFloor()
end
end
if closestPlayer and humanoidRootPart.Position.Y <= floorHeight then
chasePlayer(closestPlayer)
end
if not closestPlayer or humanoidRootPart.Position.Y > floorHeight then
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position.X, ceilingHeight, humanoidRootPart.Position.Z)
bodyVelocity.Velocity = Vector3.new(0, 0, 0)
end
wait(0.1)
end
Also its in the monster