How to make a tool that heals people around you by touching the handle?

This is so weird. I have a starter character, which might be the problem? but the humanoid’s name is humanoid

I honestly have no idea, try removing the StarterCharacter and check if it works.

Just did and it still doesn’t work!

Weird, could you show me a video?

Just tested it in another game of mine, and it didn’t work there either. I’ll get a video for ya

robloxapp-20240401-1746595.wmv (2.2 MB)

This is in a fresh game.
Here’s the code:


function onTouched(part)
   local h = part.Parent:findFirstChild("Humanoid")
   local heal =  h.MaxHealth
   if h then
   	h.Health = heal
   	wait(.5)
   end
end

script.Parent.Touched:connect(onTouched)

For some reason it gives me this error as well: Players.z71226.Backpack.HealToolTest.Handle.Script:4: attempt to index nil with ‘MaxHealth’

You are probably getting the error because the part touched the Baseplate, which doesn’t have a MaxHealth property, although i have no idea why it’s not detecting the player holding the part (probably because the part is inside the character??), it works for other characters.

This wont error if you touch anything else other than a player:

function onTouched(part)
	local h = part.Parent:FindFirstChild("Humanoid")
	if not h then return end
	
	local heal =  h.MaxHealth
	
	h.Health = heal
	wait(.5)
end

script.Parent.Touched:connect(onTouched)
1 Like

@lavasance Beat me to it!
I was going to mention that this not being inside the if h then could potentially be causing errors:

Also for future reference, use FindFirstChild instead of findFirstChild as it’s deprecated.

1 Like

Still doesn’t seem to work. Might just change the feature to just heal the own player instead of everyone around them for now. Thanks for all you’re help though! I’ll give you the solution for your trouble!

1 Like

If it still doesn’t work then it must be something wrong on your end. I see no reason for it to not work?

I’ll make what you’re asking for when I next wake up as it’s very late here. If it works I’ll send the code here and also the RBXL file for you to test it on.

If you really insist on changing it to heal the own player and you don’t want a possible solution, then I can leave this here as it is.

Understood, you are using it for yourself, like a medic-kit!! Let me test a thing.

So I’ve done some testing and I’ve gotten it to work. I tested this on a Rig and a 2 player local server.

Below I’ve attached a recording of me testing the tools and I’ve also attached the RBXL file for you to test out.

Both tools are inside StarterPack.


Healing and Damage Parts.rbxl (82.3 KB)

Here is the script for the Healing Part tool:

local debounce = false
script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid") -- Find the humanoid
	if not humanoid or humanoid.Health >= humanoid.MaxHealth or debounce then return end -- If there's a humanoid and the humanoid's health is more or equal to its max health, do nothing
	
	debounce = true -- Start the debounce
	
	humanoid.Health = math.min(humanoid.MaxHealth, humanoid.Health + 5) -- Heal the humanoid but don't heal past it's max health
	print("Healed \""..humanoid.Parent.Name.."\" for 5 health. New health:", humanoid.Health) -- Debugging purposes, just to see what it healed
	
	task.wait(0.5) -- Wait half a second
	
	debounce = false -- Reset the debounce
end)

Hope this helps!

He marked that as already solved. Anyway thanks for help him.

Eh it was worth a shot. He marked it as resolved because we tried to help him but in the end he couldn’t do it and he stated that he wanted to instead change it to heal the player holding the tool. I posted that as a last resort but thanks for the shout!

It’s working for me now! Decided to give you the solution instead

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.