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?

2 Likes

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

2 Likes

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

2 Likes

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

3 Likes

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

2 Likes

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

2 Likes

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

2 Likes

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)

2 Likes

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

2 Likes

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.

2 Likes

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

1 Like

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

1 Like
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.

2 Likes

doesn’t work sadly. (insert text here)

1 Like

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

1 Like

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!

1 Like

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

2 Likes

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)
2 Likes

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

1 Like

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.

1 Like