How to make a tool detect if it hit a player (or sum like that)

He wants his tool to physically touch the player to do damage.
How about read before you answer?

1 Like

im just trying to make a tool that when its equipped and you click. it deals damage to a player it touches.

1 Like

This guy is a rookie scripter as you can tell. He doesn’t know what that means.

1 Like

Can we stop arguing?
I’ll call a staff here.

2 Likes

bro chill down and stop arguing, lets just try to make the thing work.

1 Like

If I use a Touched event, it’ll be inconsistent anyway. If he wants to physically touch an opponent, it’s the only option.

1 Like

just ise a Touched event for god sake keep it simple like the classic riblox sword

1 Like

fine i guess. i mean, i don’t know much stuff anyway so it depends on yall if yall tryna help me or nah. (btw sorry if my english is bad, im from poland)

1 Like

introduce the dude to raycasting or region3 or workspace collision checker functions never ever use magnitude checks for hitboxs

1 Like

wait i got an idea. what if we use the “touched” thingy, so when it hits someone, we check if it’s a humanoid, if it’s a humanoid then we just take the players health, but the question is how.

1 Like

Watch the tutorial to better grasp the idea of the .Touched event.

i kind of know what “touched” event is. i actually made few scripts using it. but not the greatest scripts.

Handle.Touched:Connect(function(otherPart)
    if otherPart.Parent and otherPart.Parent:FindFirstChild("Humanoid") then
        otherPart.Parent.Humanoid:TakeDamage(1)
    end
end)

Make sure to replace “Handle” with the part you want to attack a player with.

1 Like

doesn’t work sadly. (insert text here)

You need to replace “Handle.” with the path to the part that you want to damage the player when touched.

doesnt work again. i guess i will never get it to work :frowning: i got to go because in poland its late as hell. see yall tommorow!

I ran the code and it worked.
It’s probably a typo.

1 Like

Handle.Touched might work

put the code in a serverscript in the tool

local tool = script.Parent
local cd = true
local cdtime = 1

tool.Handle.Touched:Connect(function(tpart)
	if tpart.Parent:IsA("Model") and tpart.Parent	:WaitForChild("Humanoid") and cd then
		cd = false
		tpart.Parent:WaitForChild("Humanoid"):TakeDamage(10)
		wait(cdtime)
		cd = true
	end
end)
1 Like

oh my bad [quote=“JustMrKoala, post:59, topic:2494167, full:true, username:zeermooienaam5”]
Handle.Touched might work

put the code in a serverscript in the tool

local tool = script.Parent
local cd = true
local cdtime = 1

tool.Handle.Touched:Connect(function(tpart)
	if tpart.Parent:IsA("Model") and tpart.Parent:WaitForChild("Humanoid") and cd then
		cd = false
		tpart.Parent:WaitForChild("Humanoid"):TakeDamage(10)
		wait(cdtime)
		cd = true
	end
end)

[/quote]

i had a typo this one should work

This is some inefficient code, and can lead to many errors, and completely breaking the loop in general due to a stack error.

You shouldn’t loop through the entire workspace, to find some characters.

If you are aiming to get specifically players characters you should use the :GetPlayers() method on the Players service.

Or if you have NPCs you attacking loop through the folder which are specific to the NPCs, or if you prefer you can use CollectionService and give the NPCs tags.