Hello! Someone downvoted my answer, even though I tested and it does work. This code includes a few extra features such as the transition between low health and 100 being smooth and there is a decently in-depth explanation of the code so that you can learn. I put a lot of effort into writing and testing this answer, so if this does help you, please accept it.
I found a few bugs, such as the variable name just referencing an instance, not the actual name, and also only modifying the property health on the client (remote events needed). I decided to do a rewrite that's simple, so here's my version:
LocalScript In The Tool
local tool = script.Parent
tool.Activated:Connect(function()
game.ReplicatedStorage.HealCharacter:FireServer()
end)
Now create a RemoteEvent in ReplicatedStorage and call it "HealCharacter".
Then create a script (server script/normal script) in ServerScriptService
Script In ServerScriptService
game.ReplicatedStorage.HealCharacter.OnServerEvent:Connect(function(player)
local hum = player.Character:WaitForChild("Humanoid")
local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(hum,Info,{Health=100})
Tween:Play()
end)
Everything has been tested and it works. If you want my .rblx file that I tested in, contact me on discord and I can send it to you. Green#2605
Warning: Make sure you have a Handle part if the property 'RequiresHandle' of the Tool is enabled. This will not work if the player's health is decreased locally. Which means that the when the health is lowered in the first place, it must be a server script or involve Remote Events. If you need any help with this last part, or are confused, feel free to ask me in the comments of this answer.
I really hope this helps you and you learned something!
-ProqrammedGreen
3 comments
currently working an an answer
It's not healing because the variable is referencing the object, not the name.
please read/consider both our answers/comments