application by seh
-- //MADE BY SEHELINDA FOR APPLICATIONS//
-- We get the PathFindingService
local PTS = game:GetService("PathfindingService")
-- We reference the npc character
local Npc = script.Parent
-- We reference our rootpart
local NpcRoot = Npc.HumanoidRootPart
--Wait 1 second
wait(1)
-- Get other services and debounce to avoid multiple damage
local players = game.Players:GetPlayers()
local RunService = game:GetService("RunService")
local Debounce = false
-- we make a function to get a Head of our players to raycast to their position
local function GetHead(player)
-- The function gets multiple parts, and returns end if they cant be found
local Char = player.Character or player.CharacterAdded:Wait()
if not Char then return end
local Hum = Char:WaitForChild("Humanoid")
if not Hum then return end
local Head = Char:WaitForChild("Head")
if not Head then return end
return Head
end
while true do
-- We makr a while true do loop :
for _, player in pairs(players) do
-- the key here is player, and the for loop loops through every player and getting their head
local Head = GetHead(player)
-- We reference our character
local Char = Head.Parent
if not Char then return end
-- we create new raycast params
local Params = RaycastParams.new()
-- we filter the descendants of the Npc model to avoid hitting the parts of the npc
Params.FilterDescendantsInstances = {Npc}
Params.FilterType = Enum.RaycastFilterType.Exclude
-- we get the raycast result by raycasting from the npc's root to the heads position
local RayCastResult = workspace:Raycast(NpcRoot.Position, Head.Position - NpcRoot.Position, Params)
-- if the raycasting hits a descendant of our character, we create a path
if RayCastResult and RayCastResult.Instance:IsDescendantOf(Char) then
local Path = PTS:CreatePath({
-- our agent paramaters, whether it can clim or jump
AgentCanJump = true,
AgentCanClimb = true,
})
-- we compute a path from the npc's root to the head's position
Path:ComputeAsync(NpcRoot.Position, Head.Position)
-- for every waypoint that the path created, the humanoid moves to it, jumping if neccesary
for _, waypoint in pairs(Path:GetWaypoints()) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
Npc.Humanoid.Jump = true
end
Npc.Humanoid:MoveTo(waypoint.Position)
end
end
end
task.wait(0.0001)
end
关闭于 2025-08-01 0 条评论