Adding blacklist and ignore list to ray

What are you trying to make.

If your just trying to see if a player has some sort of attachment then just raycast to see if the parent of the object is a Player with a Humanoid and then check their accessories.

1 Like

im trying to add ignore list to this ray so it ignore, player holding tool and tool parts (ik how to get these 2 just ‘:GetChildren()’), but idk how to make an ignore list and ignore the accesories

Then what is the ray supposed to detect?

its suposed to work as bullet like to stop at any non transparent obstacle and dmg players + ignore gun and player shooting it, im not sure how to add this ignore list so it wont block on the gun and player shooting it

You can add parameters to your raycast.

local UIS = game:GetService("UserInputService")
local StuffYouDontWant = workspace.StuffYouDontWant

local function mouseRaycast()
	local mousePos = UIS:GetMouseLocation()
	local mouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.BlackList
	raycastParams.FilterDescendantsInstances = {StuffYouDontWant} -- Put objects here

	local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, raycastParams)
	return raycastResult
end

I recommend using the new collision groups like so:

You could use ignore list but its difficult to get all the accessories in workspace and put it in one table while also constantly updating it for new ones. (though you could use collection services)

Something like @WhiteOut_RBLX mentioned with parent checking, but uses recasting the ray multiple times which seems less efficient than collision groups (havent done performance tests yet).

But it should work also.

Then use a blacklist with your player being the only object in there

Then in the script just make a check that sees if the part is a part of another player and if its not then just dont do anything

Or you could make a script that also turns off CanTouch in every accessory the player has and you wont have to care because the ray won’t be able to hit them.

so i can like put table i stuff i dont want, i guess but how to ignore any item wich parent is accesory? or i shoud get first ancestor wich is model and check if it have humanoid?

To check if something is an accessory, you can use Instance:IsA

To check if something has a humanoid, you can try to use :FindFirstChild and act accordingly.

--Example
local PathToACharacter

local humanoid = PathToACharacter:FindFirstChild("Humanoid")
if humanoid then
-- do something
end

what is pathtocharacter, i see it first time

It’s simply a variable for a character you want to reference.

will isA(“Accesory”) detect it on handle inside it?

It’ll detect the accessory, but not the handle. If you want to get the handle, you can check the accessory.

Example script if you would want to try it (goes inside of a character)

for i, v in script.Parent:GetChildren() do
	if v:IsA("Accessory") then
		print(v.Name) -- If you wanted the handle, you could do v.Handle
	end
end

thx i cant get parent of raycast results how i can do this

  1. Check if the raycast actually hit anything
  2. Check if the raycast hit a character and use that as a reference

I made this:
if raycastResult.parent:FindFirstChild(“Humanoid”) then
event:FireServer(raycastResult.parent:FindFirstChild(“Humanoid”))
elseif raycastResult.parent:IsA(“Accesory”) then
event:FireServer(raycastResult:FindFirstAncestorIsA(“Model”):FindFirstChild(“Humanoid”))
else
but i get this:
‘parent’ is not a valid member of RaycastResult

The object returned from the raycast result would be raycastResult.Instance

Code taken from RaycastResult

if raycastResult then
	print("Object/terrain hit:", raycastResult.Instance:GetFullName())
	print("Hit position:", raycastResult.Position)
else
	print("Nothing was hit!")
end

thx now ik how to do rest just 1 last question to what i shall parent attachment 2 and to what i shall set its location to get acurate beam as visual
(aslo i have to do this in script to get it visable for everyone not in local one, i shall use event for that i guess but how i shall move variables to visual script to dont make it messy)

https://developer.roblox.com/en-us/api-reference/class/Beam

ik how beam works i mean to wich variables i shall set location of attachment1