Check when screen clicked while holding tool?

Hey, I’m trying to make a thing where if your holding a tool and you click the screen then it gives health.
This is what I got:

local player = game:GetService("Players").LocalPlayer
player.Character.CerealBox.Activated:Connect(function(player)
	-- What goes here?
end)

Try this

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
player.Character.CerealBox.Activated:Connect(function(player)
	mouse.Button1Down:Connect(function()
        while player.Character.Humanoid.Health < 100 do
            player.Character.Humanoid.Health = player.Character.Humanoid.Health + 20
            wait(5)
        end
    end)
end)
1 Like

lol, thanks although I thought that activated was when u had the tool equipped. Sorry for the confusion. The original script works or yours does as well.

2 Likes

Activated is when you click your screen while holding the tool.

2 Likes

If this is a local script then any changes made to the player’s humanoid’s health property will not reflect to the server.

local tool = script.Parent

tool.Activated:Connect(function()
	if not tool.Enabled then return end
	local character = script.Parent
	if not character then return end
	local humanoid = character:FindFirstChildOfClass"Humanoid"
	if not humanoid then return end
	if humanoid.Health <= 0 then return end
	humanoid:TakeDamage(-humanoid.MaxHealth) --Negative value adds health.
	tool.Enabled = false
	task.wait(3)
	tool.Enabled = true
end)

Server script inside the tool.