Problems With Raycasting Not Ignoring Players

I’m not sure what I have to do, but I’m having trouble with making raycasts in my game ignore players. The script where the raycast is being fired from is a local script.

I have tried looking at other posts, but they seem to complicated and am unsure of how to implement it into my code.

1 Like

Make a table of all the player’s characters and then put that in the raycast params.

I’m not sure how to say this, but I have tried and it hasn’t worked for me.
I had the table set up and implemented, but it still didn’t work for me.

1 Like

Adding onto this reply you would have to do something like this:

local Exlude = {}

local OriginPosition = --Position here
local DirectionVector = --Direction here

for i, plr in pairs(game.Players:GetChildren()) do
	for i, part in pairs(plr.Character:GetDescendants()) do
		if part:IsA("BasePart") or part:IsA("MeshPart") then
			table.insert(Exlude, part)
		end
	end
end

print(Exlude)

local Params = RaycastParams.new(Exlude)
Params.FilterType = Enum.RaycastFilterType.Exclude

game.Workspace:Raycast(OriginPosition, DirectionVector, Params)
1 Like

Thanks so much for doing this for me.

1 Like

no problem lol, glad i could help.

this one worked for some reason out of the other scripts I used. Maybe I was reading the wrong posts. Nonetheless, thank you.

1 Like