Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mob = script.Parent
- local mobSpeed = 14
- local maxHealth = 500
- local currentHealth = maxHealth
- local respawnTime = 5
- local damagePerHit = 30
- local hitCooldown = 2
- local hitRange = 6
- local senseRange = 15
- local isCoolingDown = false
- local isAttacking = false
- local spawnCFrame = mob.HumanoidRootPart.CFrame
- local humanoid = mob.Humanoid
- humanoid.WalkSpeed = mobSpeed
- humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
- humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
- humanoid.MaxHealth = 1000000
- humanoid.Health = 1000000
- local healthGui = mob.Head.MobHealthGui
- local bar = healthGui.BarBackground.Bar
- local healthTxt = healthGui.BarBackground.HealthText
- healthTxt.Text = currentHealth .. "/" .. maxHealth
- local attackAnimation = humanoid:LoadAnimation(script:WaitForChild("AttackAnimation"))
- humanoid.Touched:Connect(function(hitPart)
- if not isAttacking then return end
- local character = hitPart.Parent
- if character:FindFirstChild("Humanoid") then
- isAttacking = false
- character.Humanoid:TakeDamage(damagePerHit)
- end
- end)
- local humCurrentHealth = humanoid.Health
- humanoid.HealthChanged:Connect(function(newHealth)
- local healthDifference = newHealth - humCurrentHealth
- humCurrentHealth = newHealth
- currentHealth = math.clamp(currentHealth + healthDifference, 0, maxHealth)
- bar.Size = UDim2.new(1/maxHealth*currentHealth, 0, 1, 0)
- healthTxt.Text = currentHealth .. "/" .. maxHealth
- if currentHealth == 0 then
- mob.Parent = game.ServerStorage
- currentHealth = maxHealth
- bar.Size = UDim2.new(1/maxHealth*currentHealth, 0, 1, 0)
- healthTxt.Text = currentHealth .. "/" .. maxHealth
- humanoid.Health = humanoid.MaxHealth
- humanoid:MoveTo(Vector3.new(0, 0, 0))
- mob.HumanoidRootPart.CFrame = spawnCFrame
- wait(respawnTime)
- mob.Parent = workspace
- end
- end)
- game:GetService("RunService").Heartbeat:Connect(function()
- local closestCharacter
- for i, player in pairs(game.Players:GetPlayers()) do
- local char = player.Character
- if char then
- local hrp = char.HumanoidRootPart
- local distanceFromMob = (mob.HumanoidRootPart.Position - hrp.Position).Magnitude
- if distanceFromMob <= senseRange then
- if not closestCharacter then closestCharacter = char
- elseif distanceFromMob < (closestCharacter.HumanoidRootPart.Position - mob.HumanoidRootPart.Position).Magnitude then closestCharacter = char end
- end
- end
- end
- if closestCharacter then
- humanoid:MoveTo(closestCharacter.HumanoidRootPart.Position)
- if not isCoolingDown and (closestCharacter.HumanoidRootPart.Position - mob.HumanoidRootPart.Position).Magnitude <= hitRange then
- isCoolingDown = true
- attackAnimation:Play()
- isAttacking = true
- attackAnimation.Stopped:Wait()
- isAttacking = false
- wait(hitCooldown)
- isCoolingDown = false
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement