Proximity Prompt Heal

Hello! I was wondering how to make a player be healed by activating a Proximity Prompt.

Here is my current script:

local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function()
game.Players.LocalPlayer.Humanoid.Health = 100
end)

script.Parent.Triggered:Connect(function(player)
player.Character.Humanoid.Health = player.Character.Humanoid.Health + 50
end)
2 Likes

Mistakes in your script-

  • You did not get the ProximityPromptService in your script

  • LocalPlayer cannot be used in a Server Script

  • Humanoid is always inside a Player’s Character

There are several was you could do that and in different instances. Put this code inside a server script.

Increasing player’s health by a fixed value-

local ProximityPromptService = game:GetService("ProximityPromptService")
local ProximityPrompt = script.Parent
local incrementValue = 20 --can be changed to any value depending upon how much health you want to increase

ProximityPrompt.Triggered:Connect(function(player)
workspace[player.Name].Humanoid.Health = workspace[player.Name].Humanoid.Health + incrementValue
print("Health increased")

end)

Increasing player’s health to the maximum health possible

local ProximityPromptService = game:GetService("ProximityPromptService")
local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function(player)
local maxHealth = workspace[player.Name].Humanoid.MaxHealth
workspace[player.Name].Humanoid.Health = maxHealth
print("Health Full")

end)

Increasing player health by a value until its full

local ProximityPromptService = game:GetService("ProximityPromptService")
local ProximityPrompt = script.Parent
local incrementValue = 10

ProximityPrompt.Triggered:Connect(function(player)
local maxHealth = workspace[player.Name].Humanoid.MaxHealth
while workspace[player.Name].Humanoid.Health < maxHealth do
wait(0.5)
workspace[player.Name].Humanoid.Health = workspace[player.Name].Humanoid.Health + incrementValue
end
print("Health Full")

end)

Hope it helps

7 Likes