RayCastingHitboxV4.01 self damages local player

I’m making a combat game and while testing one of my swords, the sword’s hitbox also damages me as well. Now the sword does damage other players but again it also damages yourself. Is there a way to make the script not damage the player that has the sword equipped?

Did you try to find any solutions? I’ve checked the devforums trying to find out who else had the same problem, but I found nothing.

Also If my grammar’s bad, I’m sorry its just that its my first time making a topic.

To check if the player you’re damaging is the player holding the sword, use a script like this:
(I’m assuming you’re dealing damage from a script inside of a sword tool.)

local userCharacter = script.Parent.Parent
if not userCharacter:FindFirstChildOfClass("Humanoid") then return false end
if CharacterYouAreDamaging ~= userCharacter then
-- Damage player
end

This obviously will change depending on the way your tool is scripted, so if it’s too vague I can provide a more in depth solution with more information on how the sword is programmed.

I’ll send my entire sword script so you can check it out.

From what I see here, I believe the best way to solve this is by adding a ‘hitFrom’ variable to the Hitbox.OnHit event to tell you which player the hit is coming from.

Hitbox.OnHit:Connect(function(hit, humanoid, hitFrom)
	print(hit.Name)
	if not hitFrom then humanoid:TakeDamage(Damage) return true end -- Damages anyways if hitfrom is nill
	if humanoid ~= hitFrom:FindFirstChildOfClass("Humanoid") then -- If hitFrom is the player itself, add .Character to hitFrom here. 
		humanoid:TakeDamage("Damage")
	end
end)

Sorry for the late reply but now it doesn’t damage other players.

Instead I get this error
image

Is RaycastResult a player’s character?
Did you do .FindFirstChildOfClass or :FindFirstChildOfClass?

Well I just tried out this module so Idk rly.
also yes I did use :FindFirstChildOfClass

Hi, I am aware it has been awhile since this post was posted to.

I am only commenting for future people with the same issue and for Bacon.

As mentioned on the official documentation for RayCastHitboxV4 it demonstrates this.

Please refer here

local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {MyCharacter} --- remember to define our character!
Params.FilterType = Enum.RaycastFilterType.Blacklist

-- We will construct a new hitbox for our sword
local newHitbox = RaycastHitbox.new(Sword)
newHitbox.RaycastParams = Params --- Define our RaycastParams

--- The raycasts will no longer damage your character or any objects you put in the ignore list!

I didn’t know too much about the params before, but I appreciate you correcting my old post.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.