Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local npc = script.Parent
- local npcHumanoid = script.Parent:WaitForChild("Humanoid")
- local npcHRP = script.Parent:WaitForChild("HumanoidRootPart")
- npcHRP:SetNetworkOwner(nil)
- local players = game:GetService("Players")
- local runService = game:GetService("RunService")
- local damage = 10
- local function Chase()
- local target = nil
- local allPlayers = players:GetPlayers()
- for i, player in pairs(allPlayers) do
- local character = player.Character
- if character then
- local playerHRP = character:FindFirstChild("HumanoidRootPart")
- if playerHRP then
- if target then
- if (npcHRP.Position - target.Position).Magnitude > (npcHRP.Position - playerHRP.Position).Magnitude then
- target = playerHRP
- end
- else
- target = playerHRP
- end
- end
- end
- end
- if target then
- npcHumanoid:MoveTo(target.Position)
- end
- end
- local debounce = false
- npcHRP.Touched:Connect(function(hit)
- local playerHumanoid = hit.Parent:FindFirstChild("Humanoid")
- if playerHumanoid and debounce == false then
- debounce = true
- playerHumanoid.Health -= damage
- wait(1)
- debounce = false
- end
- end)
- runService.Stepped:Connect(Chase)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement