Raycasting Exclude char not working

Hey, I’m trying to exclude my character out of a raycast for a gun, but it just doesn’t work.
I also checked the children of char, to see if the character was rightfully defined, and it showed all the body parts so it should work?

tool.Activated:Connect(function()
	
	if deBounce == false then
		local mouse = player:GetMouse()
		local char = tool.Parent
	
		local params = RaycastParams.new()
		params.FilterType = Enum.RaycastFilterType.Exclude
	>>> params.FilterDescendantsInstances = {char}
		
		if mouse.Target == nil then
			return
		else
			script.Sound:Play()
			local direction =  mouse.Target.Position - tool.Handle.Position
			local ray = workspace:Raycast(tool.Handle.Position, direction)
			if ray then
				local hit = ray.Instance
				local hum = hit.Parent:FindFirstChild("Humanoid")
				if not hum and hit.Parent:IsA("Accessory") then
					hum = hit.Parent.Parent:FindFirstChild("Humanoid")
				end
				if hum then
					RS.onShot:FireServer(Dmg,hum)
				end
			end
		deBounce = true
		wait(deBounceTime)
		deBounce = false
		end
		

	end

end)

does anyone know a fix for this?

you didn’t include the params in the raycast. Try this:

local ray = workspace:Raycast(tool.Handle.Position, direction, params)

I feel stupid, its always those tiny things.
this worked, thanks!

1 Like

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