local ignore = {player.Character} local hit, position, normal = workspace:FindPartOnRayWithIgnoreList(ray,ignore)
I I want it to be able to ignore things like other player's tools and hats. whats the best way to add onto the array?
Unless you're looking to update the ignore list every time a new Hat or Tool is made, then I don't know that I recommend adding them to an ignore list.
local ignore = {player.Character} local hit, position, normal = workspace:FindPartOnRayWithIgnoreList(ray,ignore) if hit ~= nil then if hit.Name == "Handle" then hit = hit.Parent.Parent; end end
I don't know that it's the most efficient solution per se, but it's the way I typically do it. Most Tools and Hats have an object inside of them called Handle, so if you're hitting a handle you can typically assume it's part of a Player or an NPC.
I've been using this feature of raycasting a lot recently. Not sure if it's the best solution but what I do is right before I draw the ray I update my ignore list. This is how I would do it to include hats and tools.
local ignore = {player.Character} local players = game:GetService("Players"):GetChildren() for i = 1, #players do local parts = player.Character:GetChildren() --Gets all parts of the character for i = 1, #parts do if parts[i]:IsA("Accessory") then --Checking for accessories ignore[#ignore + 1] = parts[i]:FindFirstChild("Handle") --Afaik all accessories only have a handle part else if parts[i]:IsA("Tool") then --Checking for tools --This section can be easily changed if you already know what your tool's structures are gonna look like, this one I provided is just the least likely to "fail" because it missed a part local toolParts = parts[i]:GetDescendants() for i = 1, #toolParts do if toolParts[i]:IsA("BasePart") then ignore[#ignore + 1] = toolParts[i] end end end end end end local hit, position, normal = workspace:FindPartOnRayWithIgnoreList(ray,ignore)
I'll usually have a function stored in a script with this when I need it. Particularly multiple times. For the tools section, I just made that most likely to get every part in case you have multipart tools. If you know your tools will only ever have a single handle part in them then that can easily be changed to:
if parts[i]:FindFirstChild("Handle") then --Double checks that the tool actually HAS a handle first ignore[#ignore + 1] = toolParts[i].Handle end
Hope this helps you out.