I want to make a tool that lowers another player's health while I'm holding the mouse down. I can do that part but how can I make it where the script gets the part clicked?
The Mouse object has a Property called Target
. This resembles the object your curser is on.
Get the Mouse's Target in a Button1Down
event - you can use an if
statement to check if the Target's Parent has a Humanoid object, and decrease health.
local plr = game.Players.LocalPlayer; --Player local mouse = plr:GetMouse(); --Player's mouse function LeftClick() local targ = mouse.Target; --This is what the mouse is on if targ then --If the mouse is actually on something --Search for a Humanoid local potentialHum = targ.Parent:FindFirstChild("Humanoid"); if potentialHum then --If there's a Humanoid print("Damage da enemy >:3"); end end end mouse.Button1Down:Connect(LeftClick) --Button1Down event on mouse