Advertisement
Me_Hker

Test

Jan 3rd, 2025 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.55 KB | Gaming | 0 0
  1. --- สคริปมอนเดินตาม ---
  2. local originalPosition = script.Parent.HumanoidRootPart.Position
  3. script.Parent.Humanoid.WalkSpeed = 34.25
  4.  
  5. local playerHit = false
  6. local lastHealth = script.Parent.Humanoid.Health
  7.  
  8. script.Parent.Humanoid.HealthChanged:Connect(function(newHealth)
  9.     local damageTaken = lastHealth - newHealth
  10.     if damageTaken > 1 then
  11.         playerHit = true
  12.     end
  13.     lastHealth = newHealth
  14. end)
  15.  
  16. function findNearestTorso(pos)
  17.     local list = game.Workspace:GetChildren()
  18.     local torso = nil
  19.     local dist = 88.5
  20.     for _, obj in ipairs(list) do
  21.         if obj:IsA("Model") and obj ~= script.Parent then
  22.             local temp = obj:FindFirstChild("HumanoidRootPart")
  23.             local human = obj:FindFirstChild("Humanoid")
  24.             if temp and human and human.Health > 0 then
  25.                 local distance = (temp.Position - pos).Magnitude
  26.                 if distance < dist then
  27.                     torso = temp
  28.                     dist = distance
  29.                 end
  30.             end
  31.         end
  32.     end
  33.     return torso
  34. end
  35.  
  36. while true do
  37.     wait(math.random(1, 2))
  38.     if playerHit then
  39.         local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
  40.         if target and not target.Parent:FindFirstChild("NPC") then
  41.             script.Parent.Humanoid:MoveTo(target.Position)
  42.         end
  43.     else
  44.         script.Parent.Humanoid:MoveTo(originalPosition)
  45.     end
  46.  
  47.     local currentPosition = script.Parent.HumanoidRootPart.Position
  48.     if (currentPosition - originalPosition).Magnitude > 88.5 then
  49.         script.Parent.HumanoidRootPart.CFrame = CFrame.new(originalPosition)
  50.     end
  51. end
  52. -------
  53.  
  54.  
  55. --- สคริปตี ---
  56. wait(1.5)
  57. local sp = script.Parent
  58. local Enemy = sp:WaitForChild("Humanoid")
  59. local Head = sp:WaitForChild("Head")
  60. local UpperTorso = sp:WaitForChild("UpperTorso")
  61. local Animation = script:WaitForChild("AttackAnim")
  62. local Animation1 = script:WaitForChild("AttackAnim1")
  63.  
  64. local Hit1 = Instance.new("Sound",UpperTorso)
  65. Hit1.Volume = 1
  66. Hit1.SoundId = " "
  67. Hit1.Pitch = 0.15
  68.  
  69.  
  70. local AttackEnabled = true
  71.  
  72. function wait(TimeToWait)
  73.     if TimeToWait ~= nil then
  74.         local TotalTime = 0
  75.         TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
  76.         while TotalTime < TimeToWait do
  77.             TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
  78.         end
  79.     else
  80.         game:GetService("RunService").Heartbeat:wait()
  81.     end
  82. end
  83.  
  84. function DamageTag(parent,damage)
  85.     local DmgTag = script.DamageTag:clone()
  86.     DmgTag.Attack.Value = damage
  87.     DmgTag.Check.Value = game.Players.LocalPlayer
  88.     DmgTag.Disabled = false
  89.     DmgTag.Parent = parent
  90. end
  91. local Anim = Enemy:LoadAnimation(Animation)
  92. local Anim1 = Enemy:LoadAnimation(Animation1)
  93. local number = 1
  94. function Hit(hit)
  95.     if hit.Parent ~= nil then
  96.         if hit.Parent:FindFirstChild("Humanoid") ~= nil and hit.Parent:FindFirstChild("Humanoid"):IsA("Humanoid") and AttackEnabled == true and TargetHum ~= Enemy then
  97.             local TargetHum = hit.Parent:FindFirstChild("Humanoid")
  98.             if not hit.Parent:FindFirstChild("NPC") then
  99.            
  100.             AttackEnabled = false
  101.             delay(1,function() AttackEnabled = true end)
  102.        
  103.             if Anim and number == 1 then Anim:Play() number = 2 end
  104.             if Anim and number == 2 then Anim1:Play() number = 1 end
  105.             DamageTag(TargetHum.Parent,5)
  106.        
  107.             Hit1:Play()    
  108.             end
  109.         end
  110.     end
  111. end
  112.  
  113. for _, Child in pairs(script.Parent:GetChildren()) do
  114.     if Child:IsA("Part") or Child:IsA("WedgePart") or Child:IsA("CornerWedgePart") then
  115.         Child.Touched:connect(Hit)
  116.     end
  117. end
  118. ---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement