1 | |
2 | |
3 | local toolName = "Heal" |
4 | local maxHealth = 100 |
5 | local healthThreshold = 19.999 |
6 | |
7 | local player = game.Players.LocalPlayer |
8 | |
9 | local function equipAndUseHealTool() |
10 | local character = player.Character or player.CharacterAdded:Wait() |
11 | local backpack = player.Backpack |
12 | |
13 | local tool = backpack:FindFirstChild(toolName) |
14 | if tool then |
15 | character.Humanoid:EquipTool(tool) |
16 | wait() |
17 | tool:Activate() |
18 | |
19 | |
20 | wait(0.0000001) |
21 | |
22 | |
23 | if character:FindFirstChild(toolName) then |
24 | local sword = backpack:FindFirstChild("Sword") |
25 | if sword then |
26 | character.Humanoid:EquipTool(sword) |
27 | end |
28 | end |
29 | end |
30 | end |
31 | |
32 | local function checkHealthAndHeal() |
33 | local character = player.Character or player.CharacterAdded:Wait() |
34 | local humanoid = character:WaitForChild("Humanoid") |
35 | |
36 | if humanoid.Health < healthThreshold then |
37 | equipAndUseHealTool() |
38 | end |
39 | end |
40 | |
41 | |
42 | local function monitorHealth() |
43 | local character = player.Character or player.CharacterAdded:Wait() |
44 | local humanoid = character:WaitForChild("Humanoid") |
45 | |
46 | humanoid.HealthChanged:Connect(function() |
47 | checkHealthAndHeal() |
48 | end) |
49 | end |
50 | |
51 | |
52 | player.CharacterAdded:Connect(function() |
53 | monitorHealth() |
54 | end) |
55 | |
56 | |
57 | monitorHealth() |