Roblox Studio. Как сделать чтобы при нажатии на ProximityPrompt Npc ходил за игроком который на него нажал?
Roblox Studio. Как сделать чтобы при нажатии на ProximityPrompt Npc ходил за игроком который на него нажал, и убивал при касании? Также надо чтобы Npc преследовал с помощью PathFindingService(обходил препятствия и т.д)
Можете пожалуйста не использовать ии?
По дате
По рейтингу
12345678910111213141516171819202122232425262728293031323334353637383940
local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")
local NPC = script.Parent
local ProximityPrompt = NPC:WaitForChild("ProximityPrompt")
local function followPlayer(player)
local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
while true do
local path = PathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentJumpHeight = 10,
AgentMaxSlope = 45,
})
path:ComputeAsync(NPC.Position, humanoidRootPart.Position)
-- Используем метод :MoveTo для NPC
path:MoveTo(NPC)
-- Ждем завершения пути
path:MoveToFinished:Wait()
wait(1)
if (NPC.Position - humanoidRootPart.Position).Magnitude < 5 then
-- Убийство игрока
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(10) -- Урон при касании
end
break
end
end
end
ProximityPrompt.Triggered:Connect(followPlayer)
Отредактировал код ещё раз попробуйте