Accessories blocking raycasting

Heya!

I’m making an assault rifle for a class-based shooter game and there’s an issue I’m trying to solve. The issue being that the raycast abruptly ends whenever hitting an enemies accessory. This basically means that if an enemy is wearing way too many accessories, they can basically negate any damage from the rifle.

--//Tool\--
local Tool = script.Parent

--//Functionality\\--
local PartCache = require(game.ServerScriptService:WaitForChild("PartCache"))
Tool.FireEvent.OnServerEvent:Connect(function(Player, MousePos)
	--//Sound
	Tool.GripPart.Firing:Play()
	
	--//Setting params so we don't kill yourself with the gun
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {Player.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	
	--//Raycasting
	local RaycastResult = workspace:Raycast(Tool.FirePart.Position, (MousePos - Tool.FirePart.Position).Unit * 500, raycastParams)
	if RaycastResult then
		--//Giving the raycast a vizuliser or whatever you call it nsdaabsdnbasdkdabjksadbjds
		local Distance = (Tool.FirePart.Position - RaycastResult.Position).Magnitude
		local RaycastPart = Instance.new("Part",workspace.Debris)
		RaycastPart.Anchored = true
		RaycastPart.CanCollide = false
		RaycastPart.Material = Enum.Material.Neon
		RaycastPart.BrickColor = BrickColor.new("New Yeller")
		RaycastPart.Size = Vector3.new(0.1, 0.1, Distance)
		RaycastPart.CFrame = CFrame.lookAt(Tool.FirePart.Position, MousePos) * CFrame.new(0, 0, -Distance/2)

		game:GetService("Debris"):AddItem(RaycastPart,0.05)
	end
	--//Damaging
	local Hit = RaycastResult.Instance
	if Hit then
		local Victim = Hit.Parent
		local Humanoid = Victim:FindFirstChildWhichIsA("Humanoid")
		
		if Humanoid and Humanoid.Health > 1 then
			Humanoid:TakeDamage(15)
			
			print("victim health remaining: "..Victim.Humanoid.Health)
		end
	end
end)

Couldn’t you add everyone’s accessories to the raycastParams’ filter?

considering ever accessory is just a part in an accessory instance and is called handle, check if hit is named handle and check its parents parent, or loop through all characters in workspace and any accessory found add to blacklist for raycast

you could add a collisiongroup to the params and have it not collide with any of the players accessories handle

raycastParams.CollisionGroup = "Raycast"
1 Like

I’ll go with this one guys since I’m still somewhat mediocre on scripting I guess. Thanks though!

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