Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I ignore hats in raycasting?

Asked by
Macbane 46
6 years ago

How can I make raycasts ignore all hats? If I used

if part:isA("accessory") then
--damage stuff here
end

Players with bigger hats would be at a disadvantage and it would be hard to detect headshots

1 answer

Log in to vote
0
Answered by
nilVector 812 Moderation Voter
6 years ago

What you are looking for is the FindPartOnRayWithIgnoreList function.

This function, as implied by its name, will return the BasePart that the specified Ray intersects, along with its point of intersection, surface normal at the point of intersection, and the material of the surface that was hit (if any such intersecting part is found, that is).

local ray = Ray.new(origin, direction)
local ignore = {} -- include parts to ignore in this table

local hit, pos, normal, material = workspace:FindPartOnRayWithIgnoreList(ray, ignore)

Please take a look at the Wiki page linked earlier to learn more about the optional parameters you can fill in while raycasting with an ignore list.

0
How do you put every player's hats in that table? I guess you could loop through all the players and get their hats and also update everytime someone respawns or joins. It doesn't seem like the right way to do it though. Macbane 46 — 6y
Ad

Answer this question