How do i add ignore list to raycasting?

as i said, FindPartOnRay only ignores 1 part. So if you want to add other parts to it just do like this:

local Hit,EndPos = game.Workspace:FindPartOnRayWithIgnoreList(BulletRay,  {HumanoidRootPart, otherpart})

use that instead, it is better if you in the future maybe want to add more parts

Does it then scan for the name ? and if the name is HumanoidRootPart is ignores it ?

Also since in my script the “ignore” dosent mean anything can i just create a local table so i dont have to replace everyhing ?

local Ignore = {HumanoidRootPart, otherpart}

Does it then scan for the name ? and if the name is HumanoidRootPart is ignores it ?

No, you need to give it a object to ignore. So just having “HumanoidRootPart” will just error. It needs to be a object.

Also since in my script the “ignore” dosent mean anything can i just create a local table so i dont have to replace everyhing ?

Well, yes you could, i would still recommend having it in the function. As then it is easier to change what it will ignore.

How do i do that ? how do i add it as a object then ?

I think you should learn atleast basic scripting first. Especially if you are making a gun.

bruh i know some basics but not all i mostly learn by doing i am a german dude i mostly use roblox wiki and dev forum if i get problems

Then add it as a object, it is exactly like doing

Part = workspace.Part

But getting the humanoidrootpart instead

But isnt it more complicated because the Player itself is a group and since i cant just create a variable
because players have different names ?

what i did is when the Hit.Parent finds HumanoidRootPart then add it to the table

Hit.Parent:FindFirstChild("HumanoidRootPart") then
 Ignore[TargetHumanoidRootPart] = true
end

To get the root of a player just do Root = player.Character.HumanoidRootPart

i think that is what you want, atleast from what i have read.
If not then please explain what you want to achieve

Dosent that get the Root of the own player himself ? i want it to ignore every possible HumanoudRootPart in the workspace

then just loop trough each player and add their root to a table that it then will ignore

Ray.new() and workspace:FindPartOnRay… are both legacy API and shouldn’t be used anymore. They’ve actually been deprecated very recently. Instead, you should use the newer and more upgraded raycasting:

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
-- blacklist is essentially the same thing as ignore list
raycastParams.FilterDescendantsInstances = {}
-- put the stuff you want in the ignore list inside that table.

local origin, direction = -- fill in with your own origin/direction

local raycastResult = workspace:Raycast(origin, direction, raycastParams)
if raycastResult then -- it's nil if it doesn't hit anything, so check
    print(raycastResult.Instance) -- the part that it hit
    print(raycastResult.Position) -- the position where the ray hit
    print(raycastResult.Material) -- the material of the part it hit
    print(raycastResult.Normal) -- the surface normal where it hit
end

Some of the benefits of this newer API is that you can reuse RaycastParams (you don’t have to re-create it every time, just once at the top of your script) AND you don’t have to create a ray object every time you want to raycast. It’s just 1 function.

Also, there’s no more checking the docs for the proper argument/return order. Since it’s a table now, you can set the options/read the result in any order you want.

11 Likes

Oh thats interesting. However i would call my self a noob scripter im scared to break the whole script when i try to add this new raycasting would you help me to set this up ?

You can use the above example I showed you, but just copy and paste your existing values into the new script. If anything breaks, you can just revert it.

Thats the problem i dont understand raycasting very good i dont know what to replace and what to change.
Askasta#6514 is my discord im free for a call if you are interested.

If you want to learn more about raycasting I’d recommend reading these articles:

All of them are pretty short and once you understand them you’ll be able to make a proper gun. All of the articles have working script samples to help you as well.

1 Like

i dont wanna make a gun myself. I just dont want a shoooting gun. My gun itself has other features aswell
how would i modificate this current one to use the new raycast

I already provided an example which shows you how to use the new raycasting and gave you additional resources to help you. If you don’t want to learn how, then I don’t want to help you (i’m not going to spoonfeed).

1 Like

its not about the how. Its just the current one when you hit a object wich it should wallbang it then hits the object and behind the object create a new ray.

Also it has a feature if the player mouse is aiming somehwere it cant shoot meaning behind him the gun will then switch to the gun barrel and just shoot foward. this is to disable people shooting behind them

idk how to do that

also the gun has a jam feature it has the ability to switch to gangster animation making you hold the gun sideways.

i dont know how to do all that buddy im a script modificator not a creator sadly :C

1 Like