Tool is damaging me despite my raycast parameters

Im trying to make a crowbar similar to half life, but the tool seems to damage me despite my raycast params

I Tried adding a check for the player but that was pointless, and I also tried looking at some forum posts but none of them seemed to help.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
-- blacklist is essentially the same thing as ignore list
raycastParams.FilterDescendantsInstances = {char,tool}

tool.Activated:Connect(function()
    if debounce == false then
        debounce = true
        Animation2:Play()
        local Rayc = workspace:Raycast(workspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.LookVector * 4, raycastParams)
        if Rayc then
            local Hit = Rayc.Instance
            script.Parent.RemoteEvent:FireServer(Hit)
            print(Hit)
        end
        wait(.3)
        debounce = false
    end
end)

Edit: I realize it would be useful if you had an example, so here:
https://gyazo.com/ad30cd151e875240037a9c45c72c385f

1 Like

if enemyCharacter ~= player.Character then

thats what i was referring to with the check

if Hit.Parent ~= plr.Character or Hit.Parent.Parent ~= plr.Character then
		local EnemyHum = Hit.Parent:FindFirstChild("Humanoid") or Hit.Parent.Parent:FindFirstChild("Humanoid")
		if EnemyHum then
			if debounce == false then
				debounce = true
				EnemyHum:TakeDamage(10)
				wait(0.3)
				debounce = false
			end
		end
	end

Instead of filtering the descendant instances in the start, try doing this when the player equips the tool

-- PSEUDO CODE
tool.Equipped:Connect(function()
     local char = tool.Parent
     raycastParams.FilterDescendantsInstances = {char,tool}
end)

i tried it but no luck unfortunately

Tools are descendants of their characters when they are ‘Activated’ anyway so they don’t need to be added to the arrays of filtered instances. If I had to guess, the way you’re defining ‘char’ is likely incorrect.

2 Likes

Wait actually upon looking again I see that the character reference is under the param setup, so you were correct and it works now that its fixed!