Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- สคริปมอนเดินตาม ---
- local originalPosition = script.Parent.HumanoidRootPart.Position
- script.Parent.Humanoid.WalkSpeed = 34.25
- local playerHit = false
- local lastHealth = script.Parent.Humanoid.Health
- script.Parent.Humanoid.HealthChanged:Connect(function(newHealth)
- local damageTaken = lastHealth - newHealth
- if damageTaken > 1 then
- playerHit = true
- end
- lastHealth = newHealth
- end)
- function findNearestTorso(pos)
- local list = game.Workspace:GetChildren()
- local torso = nil
- local dist = 88.5
- for _, obj in ipairs(list) do
- if obj:IsA("Model") and obj ~= script.Parent then
- local temp = obj:FindFirstChild("HumanoidRootPart")
- local human = obj:FindFirstChild("Humanoid")
- if temp and human and human.Health > 0 then
- local distance = (temp.Position - pos).Magnitude
- if distance < dist then
- torso = temp
- dist = distance
- end
- end
- end
- end
- return torso
- end
- while true do
- wait(math.random(1, 2))
- if playerHit then
- local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
- if target and not target.Parent:FindFirstChild("NPC") then
- script.Parent.Humanoid:MoveTo(target.Position)
- end
- else
- script.Parent.Humanoid:MoveTo(originalPosition)
- end
- local currentPosition = script.Parent.HumanoidRootPart.Position
- if (currentPosition - originalPosition).Magnitude > 88.5 then
- script.Parent.HumanoidRootPart.CFrame = CFrame.new(originalPosition)
- end
- end
- -------
- --- สคริปตี ---
- wait(1.5)
- local sp = script.Parent
- local Enemy = sp:WaitForChild("Humanoid")
- local Head = sp:WaitForChild("Head")
- local UpperTorso = sp:WaitForChild("UpperTorso")
- local Animation = script:WaitForChild("AttackAnim")
- local Animation1 = script:WaitForChild("AttackAnim1")
- local Hit1 = Instance.new("Sound",UpperTorso)
- Hit1.Volume = 1
- Hit1.SoundId = " "
- Hit1.Pitch = 0.15
- local AttackEnabled = true
- function wait(TimeToWait)
- if TimeToWait ~= nil then
- local TotalTime = 0
- TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
- while TotalTime < TimeToWait do
- TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
- end
- else
- game:GetService("RunService").Heartbeat:wait()
- end
- end
- function DamageTag(parent,damage)
- local DmgTag = script.DamageTag:clone()
- DmgTag.Attack.Value = damage
- DmgTag.Check.Value = game.Players.LocalPlayer
- DmgTag.Disabled = false
- DmgTag.Parent = parent
- end
- local Anim = Enemy:LoadAnimation(Animation)
- local Anim1 = Enemy:LoadAnimation(Animation1)
- local number = 1
- function Hit(hit)
- if hit.Parent ~= nil then
- if hit.Parent:FindFirstChild("Humanoid") ~= nil and hit.Parent:FindFirstChild("Humanoid"):IsA("Humanoid") and AttackEnabled == true and TargetHum ~= Enemy then
- local TargetHum = hit.Parent:FindFirstChild("Humanoid")
- if not hit.Parent:FindFirstChild("NPC") then
- AttackEnabled = false
- delay(1,function() AttackEnabled = true end)
- if Anim and number == 1 then Anim:Play() number = 2 end
- if Anim and number == 2 then Anim1:Play() number = 1 end
- DamageTag(TargetHum.Parent,5)
- Hit1:Play()
- end
- end
- end
- end
- for _, Child in pairs(script.Parent:GetChildren()) do
- if Child:IsA("Part") or Child:IsA("WedgePart") or Child:IsA("CornerWedgePart") then
- Child.Touched:connect(Hit)
- end
- end
- ---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement