Tool not adding health to player when used

So I made a food. That adds health to the player when used.

When I try it. It doesn’t give any health

CODE -

local tool = script.Parent
local eatSound = tool.Handle.eat
local equipSound = tool.Handle.equip
local cooldown = false


tool.Equipped:Connect(function()
	equipSound:Play()
end)

tool.Activated:Connect(function()
	if cooldown == false then
		cooldown = true
		local humanoid = tool.Parent:FindFirstChild("Humanoid")
		eatSound:Play()
		humanoid.Health += 25
		tool.GripForward = Vector3.new(-.981, .196, 0)
		tool.GripPos = Vector3.new(-.5, -0.6, -1.5)
		tool.GripRight = Vector3.new(0, -0, -1)
		tool.GripUp = Vector3.new(0.196, .981, 0)
		wait(0.9)
		tool.GripForward = Vector3.new(-1, 0, 0)
		tool.GripPos = Vector3.new(-.5, -.1, 0)
		tool.GripRight = Vector3.new(0, 0, 1)
		tool.GripUp = Vector3.new(0,1,0)
		wait(3)
		cooldown = false
	end
end)

1 Like

Have you confirmed that the given code runs? And also, are you receiving any errors in the output?

is this a serverscript or local script?

The script is a server script…

I’m not receiving any errors. Rest of the code works. Except the health line

Have you checked the humanoid’s health in the Properties tab and made sure that the humanoid’s health really doesn’t change?

One thing you should do is to make an if statement checking if the humanoid exists before running the rest of the code.

local tool = script.Parent
local eatSound = tool.Handle.eat
local equipSound = tool.Handle.equip
local cooldown = false


tool.Equipped:Connect(function()
	equipSound:Play()
end)

tool.Activated:Connect(function()
	if cooldown == false then
		cooldown = true
		local humanoid = tool.Parent:FindFirstChild("Humanoid")
		if humanoid then -- if humanoid exists
			eatSound:Play()
			humanoid.Health += 25
			tool.GripForward = Vector3.new(-.981, .196, 0)
			tool.GripPos = Vector3.new(-.5, -0.6, -1.5)
			tool.GripRight = Vector3.new(0, -0, -1)
			tool.GripUp = Vector3.new(0.196, .981, 0)
			wait(0.9)
			tool.GripForward = Vector3.new(-1, 0, 0)
			tool.GripPos = Vector3.new(-.5, -.1, 0)
			tool.GripRight = Vector3.new(0, 0, 1)
			tool.GripUp = Vector3.new(0,1,0)
			wait(3)
			cooldown = false
		end
	end
end)

It finds the humanoid. I checked the properties. On there. It still doesn’t change

Lemme restart studio to see if it’s a bug

Still doesn’t work [fillerrrrr]

Try using this code:

local tool = script.Parent
local eatSound = tool.Handle.eat
local equipSound = tool.Handle.equip
local cooldown = false


tool.Equipped:Connect(function()
	equipSound:Play()
end)

tool.Activated:Connect(function()
	if cooldown == false then
		cooldown = true
		local humanoid = tool.Parent:FindFirstChild("Humanoid")
		if humanoid then -- if humanoid exists
			eatSound:Play()
			humanoid.Health += humanoid.MaxHealth * .25 -- adds 25% health based on the humanoid's 'MaxHealth'
			tool.GripForward = Vector3.new(-.981, .196, 0)
			tool.GripPos = Vector3.new(-.5, -0.6, -1.5)
			tool.GripRight = Vector3.new(0, -0, -1)
			tool.GripUp = Vector3.new(0.196, .981, 0)
			wait(0.9)
			tool.GripForward = Vector3.new(-1, 0, 0)
			tool.GripPos = Vector3.new(-.5, -.1, 0)
			tool.GripRight = Vector3.new(0, 0, 1)
			tool.GripUp = Vector3.new(0,1,0)
			wait(3)
			cooldown = false
		end
	end
end)

It still doesn’t work. I don’t know why it’s doing this

It looks like. It’s refusing to add health

Try adding the humanoid’s health in another script, and see if the humanoid’s health changes.

Could you try humanoid:TakeDamage(-25)?

This will work, i tested:

local tool = script.Parent
local eatSound = tool.Handle.eat
local equipSound = tool.Handle.equip
local cooldown = false


tool.Equipped:Connect(function()
	equipSound:Play()
end)

tool.Activated:Connect(function()
	if cooldown == false then
		cooldown = true
		local humanoid = tool.Parent:FindFirstChild("Humanoid")
		if humanoid then
			eatSound:Play()
			humanoid.Health = humanoid.Health + 25
			tool.GripForward = Vector3.new(-.981, .196, 0)
			tool.GripPos = Vector3.new(-.5, -0.6, -1.5)
			tool.GripRight = Vector3.new(0, -0, -1)
			tool.GripUp = Vector3.new(0.196, .981, 0)
			wait(0.9)
			tool.GripForward = Vector3.new(-1, 0, 0)
			tool.GripPos = Vector3.new(-.5, -.1, 0)
			tool.GripRight = Vector3.new(0, 0, 1)
			tool.GripUp = Vector3.new(0,1,0)
			wait(3)
			cooldown = false
		end
	end
end)

1 Like

I try that. It goes to 125 instead of 75

Try using: Humanoid.Health=Humanoid.Health+25

(im on mobile and cant add special characters)

1 Like

Still doesn’t work. [fillerrrrr]

Can you show the explorer view of the tool and the script.

Screen Shot 2022-12-25 at 3.50.34 PM