Trouble with mouse.Target and not being able to get humanoid because of accesories

I’m Having Trouble with my ability, which is a sukuna style cut ability that when you click on someone it deals 5 damage and plays a sound. The issue is whenever the raycast / mouse.Target encounters an accessory it freaks out… or should i say doesn’t freak out because it doesn’t do ANYTHING. i have tried multiple ways of checking if its an accessory and finding the humanoid if it is but nothings working

for context, i don’t want the accessories to trigger it, but i want the raycast to be able to go through it and hit the humanoid if it were angled right to do that, like shown in the vid below, so simply i want it to go through the front accessory but obviously i don’t want the trail to trigger it.

Here is a example of me doing this and getting the print statements:

And Here Is My Code:

local tool = script.Parent
local RemoteEvent = tool["cut sorcery event"]

RemoteEvent.OnServerEvent:Connect(function(player, mouseTarget)
	print("Target:",mouseTarget,"Target Parent:", mouseTarget.Parent)
	if mouseTarget.Parent:FindFirstChild("Humanoid") then
		local humanoid = mouseTarget.Parent.Humanoid
		local humanoidRootPart = mouseTarget.Parent.HumanoidRootPart
		local sound = Instance.new("Sound")
		-- sound stuff
		sound.Parent = humanoidRootPart
		sound.Volume = 0.75
		sound.RollOffMaxDistance = 75
		sound.RollOffMinDistance = 0
		sound.RollOffMode = Enum.RollOffMode.Linear
		-- finisher check
		if humanoid.Health <= 15 then
			sound.SoundId = "rbxassetid://5754301788"
			sound:Play()
			humanoid:TakeDamage(100)
		else
			sound.SoundId = "rbxassetid://935843979"
			sound:Play()
			humanoid:TakeDamage(5)
		end
		
	end
end)

Local Script firing the server:

local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local RemoteEvent = tool["cut sorcery event"]
local debounce = false

tool.Activated:Connect(function()
	if not debounce then
		local mousePos = mouse.Target
		RemoteEvent:FireServer(mousePos)
		debounce = true
		task.delay(0.15, function()
			debounce = false
		end)
	end
end)

Please help me solve this issue!

1 Like

That’s because mouse.Target returns a BasePart, and accessories use the Accessory class with a part called “Handle” inside of them.

Instead of .Parent, try using :FindFirstAncestorWhichIsA("Model") so that it recursively checks for every ancestor until it hits a model

while @sponguswastaken’s solution works, it also means some players could theoretically have a HUUUGE hitbox compared to others… so a simpler solution could just be checking if a part is CanCollide off (and obviously making sure it is not just parented to a player).

my dumbass just realised that’s not how mouses work, so instead lets completely remake the way the mouse works using RAYCASTING! by checking if your ray hits something and continuing if it is not a character’s part :DDDDD

local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()

local camera = workspace.CurrentCamera

local function cast(origin, direction, to_ignore)
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {player.Character, table.unpack(to_ignore)}
	
	local ray = workspace:Raycast(origin, direction.LookVector * 2048, params)
	if ray then
		local part = ray.Instance
		local model = part.Parent
		if model:IsA("Model") then
			local humanoid = model:FindFirstChildOfClass("Humanoid")
			if humanoid then
				return ray
			end
		end
		
		table.insert(to_ignore, part)
		return cast(origin, direction, to_ignore)
	end
	
	return false
end

mouse.Button1Down:Connect(function()
	local origin = camera.CFrame.Position
	local direction = mouse.Hit
	local result = cast(origin, CFrame.new(origin, direction.Position), {})
	print(result)
end)

i am so sorry LMAOO