Issues with raycast filtering the users character

So what i am trying to do is make a combat script, and my main source of that registering is raycasting. So whenever i try to punch my body moves of animations but my raycast keeps hitting my arms or torso before it hits a player.

What my problem is that i am having issues with filtering out the character so the raycast would phase through my own character and succesfully hit the enemy.

I have tried all the possible ways i know which is, trying to include only my own hitbox which will blacklist everything, trying to blacklist my own character with specifically naming the body parts, filtering out all body parts with :GetChildren() and none seem to work for me. If anyone knows why the filtering system isn’t working.

Here is a screenshot, i marked some areas to note so you would understand:

3 Likes

I meant here that i want it to phase through me in order to hit a player

2 Likes

You dont need to add :GetChildren(), it will already filter them, hence RaycastParams.FilterDescendantsInstances

1 Like

didn’t work, i’ve tried all possible ways as i described

1 Like

1 Like

You are putting a table in a table which I believe doesn’t work. You can put {YHRP.Hitbox} and plr.Character:GetChildren() I am pretty sure this will work.

2 Likes

can you write it in script i didn’t fully understand, sorry.

Nope, it wont. Just replace the table with {YHRP.Hitbox, plr.Character}

Nevermind, i figured out the problem.

In your raycast, you arent adding the table.

3 Likes

this solution doesn’t work either

oh i didn’t seee your edit my bad

Add a comma, then add the filter table at the raycast function


like this or i dont know what you mean

No, after the vector3.new(), add a comma like this:

local RayCastResult = workspace:Raycast(YHRP.Position, YHRP.CFrame.LookVector * 6 + Vector3.New(0, 1, 0), RayParams)

The 3rd argument of a raycast is the params. You just forgot to add it.

1 Like

Recieved a error called, unabled to cast dictionary to raycastparams

Show me your script. Copy and paste it here using the ‘````’ symbols.
Only paste the combat part. (the part with the problem

i send the thing above, the error recieved was from the raycastresult thing.

Alright, I understand, but I need your script. your CURRENT script.

local RayParams = RaycastParams.new()

RayParams.FilterType = Enum.RaycastFilterType.Exclude
RayParams.FilterDescendantsInstances = {YHRP.Hitbox, plr.Character:GetChildren()}
RayParams.IgnoreWater = true
print(plr)

--Debris:AddItem(UserAttacking, 0.2)

SWFXP(plr) --Swing sound effect

AFXP(plr, YHRP, CurrentCombo) --Animation Combo Loading

--STUN YPLR

spawn(function()
	PLRSW(plr)
end)



task.wait(0.25)

– if plr:FindFirstChild(“Stunned”) then return end

local RayCastResult = workspace:Raycast(YHRP.Position, YHRP.CFrame.LookVector * 6 + Vector3.new(0, 1, 0), RaycastParams)

print(RayCastResult)

error came from the raycastresult variable

Change it to this:

local RayParams = RaycastParams.new()

RayParams.FilterType = Enum.RaycastFilterType.Exclude
RayParams.FilterDescendantsInstances = {YHRP.Hitbox, plr.Character}
RayParams.IgnoreWater = true
print(plr)

--Debris:AddItem(UserAttacking, 0.2)

SWFXP(plr) --Swing sound effect

AFXP(plr, YHRP, CurrentCombo) --Animation Combo Loading

--STUN YPLR

spawn(function()
	PLRSW(plr)
end)



task.wait(0.25)
-- if plr:FindFirstChild(“Stunned”) then return end

local RayCastResult = workspace:Raycast(YHRP.Position, YHRP.CFrame.LookVector * 6 + Vector3.new(0, 1, 0), RayParams)

print(RayCastResult)
1 Like