For some reason, RaycastHitbox takes accounts for accessory handles which makes detecting bodyparts being hit kind off tedious, how do I make the module ignore them but still damage?
I’m trying to achieve something like this, it works but the whole connection voids if the player has so many big accessories since they’ll most likely cover up the player bodyparts which results in them taking no damage.
local Hits = {
["Head"] = function(Victim:Humanoid?)
local Character = Victim.Parent
Character:FindFirstChild("Head").LimbHealth.Value = 0
Victim:TakeDamage(100)
end,
["Right Leg"] = function(Victim:Humanoid?)
local Character = Victim.Parent
Character:FindFirstChild("Right Leg").LimbHealth.Value -= 25
Victim:TakeDamage(45)
end,
}
HitBox.OnHit:Connect(function(Hit, Humanoid)
if Hit ~= "Handle" then -- Main issue
Hits[Hit](Humanoid)
end
end)
One way to ignore the accessory handles while still causing damage to the body parts would be to check if the hit part’s parent is the character’s HumanoidRootPart. If it is, then apply the damage as usual. Otherwise, if the hit part’s parent is an accessory, find its ancestor which is a descendant of the HumanoidRootPart and apply the damage to that part instead.
Here is an updated version of your code that implements this approach:
local Hits = {
["Head"] = function(Victim:Humanoid?)
local Character = Victim.Parent
Character:FindFirstChild("Head").LimbHealth.Value = 0
Victim:TakeDamage(100)
end,
["Right Leg"] = function(Victim:Humanoid?)
local Character = Victim.Parent
Character:FindFirstChild("Right Leg").LimbHealth.Value -= 25
Victim:TakeDamage(45)
end,
}
HitBox.OnHit:Connect(function(Hit, Humanoid)
local hitPart = Humanoid.Parent:FindFirstChild(Hit)
if hitPart then
local hitParent = hitPart.Parent
if hitParent == Humanoid.RootPart then
-- hit part is a body part
Hits[Hit](Humanoid)
else
-- hit part is an accessory
while hitParent and hitParent ~= Humanoid.RootPart do
hitParent = hitParent.Parent
end
if hitParent then
Hits[Hit](Humanoid.Parent:FindFirstChild(hitParent.Name))
end
end
end
end)
This code checks if the hit part is a child of the HumanoidRootPart, and if so, applies the damage to the appropriate body part. If the hit part is an accessory, it loops through its ancestors until it finds one that is a child of the HumanoidRootPart. Once it finds that part, it applies the damage to the appropriate body part.
This approach should allow you to apply damage to the appropriate body parts while ignoring the accessory handles.
First of all, ignore the person using ChatGPT above me lol
This can still take in any object as the paramater, so this wouldn’t do much. It only really tells you what is supposed to go in there, as well as it gives you the properties and events of that type.
Here has a couple issues.
Firstly I don’t know what OnHit is supposed to be, nor can I find it anywhere on the roblox documentation, so I’m going to assume you meant to use a Touched event. If you can explain what OnHit is supposed to be, I’d appreciate that
Secondly I do not understand why you are comparing what would be a BasePart in a Touched event to a string
Third of allTouched events only give take one paramater, which is a BasePart.
Again, I would greatly appreciate if you could tell me what OnHit is supposed to be.
Here is what I would replace the bottom event with. This should hopefully work, and it will make all of the functions inside of the Hits table work just fine with no worries of anything going wrong:
HitBox.Touched:Connect(function(Hit)
local character = hit.Parent
if character and character:FindFirstChild("Humanoid") then
Hits[Hit](character.Humanoid)
end
end)
I’ve never seen this event before honestly. And the fact that it isn’t on the documentation confuses me. But thank you for telling me. That is what I assumed, but I just needed reassurance lol
This is regarding a specific module called RaycastHitboxing, OnHit is a function from said module. Your solution describes a normal block hitbox, the other dude is actually correct, he’s not using ChatGPT.
This makes more sense. Thank you. Much appreciated.
Also, just go through all of his replies. It is so incredibly obvious they are, as well as extremely frustrating and annoying because they’re trying to grind solutions with a literal AI. Not to mention rude to people or flagging their post when calling him out on it. And I cannot stress this enough to people, they literally called me a transphobic slur the first time I called them out on it. Even after that, they either only got one strike on the forum, or simply no punishment at all.