Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local npc = script.Parent
- local rightHand = script.Parent.RightHand
- local leftHand = script.Parent.LeftHand
- local isCooldown = false
- function getClosestPlayer()
- local Closest_player = nil
- local closest_distance = 200
- for i, v in pairs(workspace:GetChildren()) do
- if v:FindFirstChild("Humanoid") and v ~= npc then
- local distance = (npc.PrimaryPart.Position - v.PrimaryPart.Position).Magnitude
- if distance < closest_distance then
- Closest_player = v
- closest_distance = distance
- end
- end
- end
- return Closest_player, closest_distance
- end
- function damage(hit)
- if hit.Parent:FindFirstChild("Humanoid") and not isCooldown then
- isCooldown = true
- local humanoid = hit.Parent:FindFirstChild("Humanoid")
- humanoid:TakeDamage(20)
- wait(0.1)
- isCooldown = false
- end
- end
- rightHand.Touched:Connect(damage)
- leftHand.Touched:Connect(damage)
- while wait() do
- local player, distance = getClosestPlayer()
- if player and distance > 10 then
- npc.Humanoid:MoveTo(player.PrimaryPart.Position)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement