Make a humanoid react when I give he a tool object

Hello, I would know how to make the player earn a point when he give a tool object to a humanoid. That very important. Please help me to find a tutorial video.

1 Like

You can use Tool.Equipped:Connect() to fire a function when a tool is equipped.

2 Likes

It does not work like that. The player must click on a humanoid with the tool equipped.

1 Like

Oh. Your title does not make the clear. " Make a humanoid react when I give he a tool object "

You can check if a new child has been added to the NPC and see if the new part is the tool.

How to detect the humanoid than player clicked?

-- Local Script
local tool = script.Parent
local event = tool:WaitForChild("HumanoidEvent")
local player = game.Players

tool.Activate:Connect(function()
	local char = tool.parent
	local plr = game.Players:GetPlayerFromCharacter(char)
	local mouse = plr:GetMouse()
	
	local part = mouse.Target
	if part.Parent:FindFirstChildWhichIsA("Humanoid") then
		local targetHumanoid = part.Parent:FindFirstChildWhichIsA("Humanoid")
		event:FireServer(targetHumanoid)
	end
end)	
1 Like

The script should be client-sided and placed inside the tool;
Then you’d need to send an event to the server-sided script which would do the action.

Then the tool would need a RemoteEvent inside it called "HumanoidEvent"

The server script should be:

-- Server script
local tool = script.Parent
local event = local event = tool:WaitForChild("HumanoidEvent")

event.OnServerEvent:Connect(function(plr,humanoid)
	-- code here
end)

Do whatever with the humanoid here