Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my tool not heal my character?

script.Parent.Activated:Connect(function(Activated)
		game.Players.LocalPlayer.Character.Humanoid.Health = game.Players.LocalPlayer.Character.Humanoid.Health + 2
end)

2 comments

0

Errors?

0

Try first making a variable that gets the humanoid, and also use player.CharacterAdded:Wait() so it does not error

2 answers

✓ Accepted answer

Editing from what @thatwalmartman said in his answer. Because this is a local script it will not be server sided. To make it server sided you do not need a RemoteEvent though, if you put a server script inside the Tool, we can get the character from the script by using script.Parent.Parent. Because we have the local Character variable inside the Tool.Activated() event it will get the Character when the Tool is Activated, and the tool cannot be activated unless it is inside the Character, this is why this will work.

Code(ServerScript):

local Tool = script.Parent

Tool.Activated:Connect(function()
	
	local Character = script.Parent.Parent
	local Humanoid = Character:WaitForChild("Humanoid")
	
	Humanoid.Health = Humanoid.Health + 5
	
end)

If this is in a LocalScript, any changes made to the player's Health will not replicate. What you would need to do instead is set up a RemoteEvent to give the health to the player or something similar to make sure it actually replicates to the server.

2 comments

0

@NiceDerpling, do what this guy tells, and structure your code like @xinfnityBear did.. both are good parts of the resulting code

0

Yeah I edited my code. RemoteEvents for this is not required.

This discussion is preserved as it was. New answers, comments, and votes are closed.