Health Potion not working

Help!
I’m trying to make a potion script, this is what’s already added on the script.

when you click, the anim plays, then the effects apply on you, your health goes to 100.But it isn’t working.

Heres what I want added: When the health applies on you, the tool gets deleted from your inventory, but the health still applies.

Heres the code:

local drinkAnim = script:WaitForChild("DrinkAnimation")

local drinkSound = script:WaitForChild("DrinkSound")

local potion = script.Parent

potion.Activated:Connect(function()
	
	if not potion:FindFirstChild("Contents") then return end
	local char = potion.Parent
	local humanoid = char:FindFirstChild("Humanoid")
	
	if humanoid then
		
		local loadedAnim = humanoid:LoadAnimation(drinkAnim)
		loadedAnim:Play()
		drinkSound:Play()
		loadedAnim.Stopped:Wait()
		potion.Contents:Destroy()
		humanoid.Health = 100
	end
end

What happens currently? Any errors? Try printing through out the script and see where it stops.

What type of script is it? It may vary depending on where you’re wanting to change the Humanoid's Health

the normal humanoid health is 100

potion.Parent is the Backpack?, maybe do potion.Parent.Parent? if your trying to get the Humanoid.

(I could possibly be very wrong on this point)

EDIT: Dont bother correcting me, I have already been corrected by 3 people :neutral_face: :grimacing:

1 Like

Well when its equipped the tool gets placed into the player leaving the players backpack.

This is through a Activated Event, so potion.Parent.Parent would be referring to:

Script > Tool > Character

Since the Character Model has the tool equipped

Oh, ok… Well I guess I learn something new everyday :sweat_smile: :grinning: :+1:

when you equip a tool the tools parent becomes the character

I KNOW WHATS WRONG you deleted the tool before you changed your health it has to be it

What…?

The tool didn’t get deleted, but rather a children’s object inside that tool did

1 Like

Okay so, the script works and all. But the only thing that doesn’t work is humanoid.health. It doesn’t change my health to 100, it stays the same. Also is there a way to make the tool destroy after the health goes to 100?

Again I will ask: Is this on a Server or Local script?

isnt the the script part of the contents???

The contents of the tool is being Destroyed, not the tool itself? :thinking:

okay

to make the tools contents delete after humanoids health is 100 is to change the order

Try putting a print(“some text here”) before and after the health part.

1 Like

Well, deleting the Tool upon activation would be easy enough by doing tool:Destroy()

Maybe you could do a print() check to see if the humanoid’s health has changed? Try this:

local drinkAnim = script:WaitForChild("DrinkAnimation")

local drinkSound = script:WaitForChild("DrinkSound")

local potion = script.Parent

potion.Activated:Connect(function()
	
	if not potion:FindFirstChild("Contents") then return end
	local char = potion.Parent
	local humanoid = char:FindFirstChild("Humanoid")
	
	if humanoid then
		print("Playing Animation")
		local loadedAnim = humanoid:LoadAnimation(drinkAnim)
		loadedAnim:Play()
		drinkSound:Play()
		loadedAnim.Stopped:Wait()
        print("Humanoid's Health Changed")
		humanoid.Health = 100
        potion:Destroy()
	end
end

to
humanoid.Health = 100
potion.Contents:Destroy()