He wants his tool to physically touch the player to do damage.
How about read before you answer?
im just trying to make a tool that when its equipped and you click. it deals damage to a player it touches.
This guy is a rookie scripter as you can tell. He doesnât know what that means.
Can we stop arguing?
Iâll call a staff here.
bro chill down and stop arguing, lets just try to make the thing work.
If I use a Touched event, itâll be inconsistent anyway. If he wants to physically touch an opponent, itâs the only option.
just ise a Touched event for god sake keep it simple like the classic riblox sword
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)
introduce the dude to raycasting or region3 or workspace collision checker functions never ever use magnitude checks for hitboxs
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.
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.
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 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.
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)
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.