Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to make a raycast ignore everything but one part?

so the title explains it all so i want it to ignore everything but one part ive tried using findpartonraywithwhitelist but it comes out with an error Unable to cast value to Objects the line is this:

local _,Position,norm = workspace:FindPartOnRayWithWhitelist(raycast, part)

plz help also this says that FindPartOnRayWithWhitelist is a thing but i am having trouble with it

1 comment

0

Make sure your parameters match. Did you see my answer to your original question?

2 answers

✓ Accepted answer
local SpecialParts = workspace.Folder -- the folder that holds all the parts that won't be ignored
local Ignored = {} -- table
local racast = Ray.new(OriginalPos, Direction) -- ray
for i, f in pairs(SpecialParts:GetChildren()) do -- all the parts that will not be ignored
    for i, v in pairs(workspace:GetDescendants()) do -- **all** parts in workspace
        if v:IsA("Part") then -- detecting if is a part
            if v ~= f then -- if the parts are not the "special" ones
                table.insert(Ignored, v) -- inserting all the ignored parts
            end
        end
    end
end
local ignore = workspace:FindPartOnRayWithIgnoreList(raycast, Ignored) -- the ignored parts


https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartOnRayWithIgnoreList

https://developer.roblox.com/en-us/api-reference/function/Instance/GetDescendants

https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren

You can Try This

local IgnoredList = {}
local racast = Ray.new(OriginalPos,Direction) --- case sensitive
local MyFavPart =---- this will be the part that wont be ignored
for _,Child in pairs (workspace:GetChildren()) do
	if Child.Name ~= MyFavPart.Name then --- make sure myfavpart has a different name from any other objects
	table.insert(IgnoredList,Child) ---- adding the part to the ignored list
end
local Launcher,Position = Workspace:FindPartOnRayWithIgnoreList(raycast,IgnoredList)

after this while loop the Launcher hope this works

3 comments

0

you're missing an end btw

1

so i don't want to rename every single part because the favpart can potentally be any part in the workspace so on line 5 i was wondering could i do if Child ~= MyFavPart then?

0

also what if the part is in a folder in workspace?

This discussion is preserved as it was. New answers, comments, and votes are closed.