Help with tool scripting

How would I be able to make a tool when a player is clicked it can damage them by 25 but only when the tool is being held?

In a Script inside of the Tool:

script.Parent.Activated:Connect(function()
    script.Parent.Parent:WaitForChild("Humanoid"):TakeDamage(25)
end)

I meant on other players, sorry.

You mean all other (than you) players on the server right?

Only when a certain player is clicked on.

Make sure to put a remote event in replicates storage and name it “DamageEvent”

Local script, a child of the tool.

local tool = script.parent

local event = game.ReplicatedStorage:WaitForChild("DamageEvent")


tool.Activated:Connect(function()
       local target = mouse.Target
       if target and target.Parent:FindFirstChild(“Humanoid”) then
              event:FireServer(target.Parent)
       end
end)



Server script:

local event = game.ReplicatedStorage:WaitForChild("DamageEvent")

event.OnServerEvent:Connect(function(player, char)
     chat.Humanoid:TakeDamage(25)
end)
1 Like