Goal To make a part that face the player using a ray, and using a table to collect all of the descendants of the player except for the HumanoidRootPart so the body parts in the table would be ignored by the ray.
Script
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local BodyParts = {}
for i,v in pairs(game.Players:GetChildren()) do
for _,p in pairs(v.Character:GetDescendants()) do
if not p.Name == "HumanoidRootPart" then
BodyParts[p] = p
table.insert(BodyParts, script.Parent)
end
end
end
local function PlayerTarget(A)
RunService.Heartbeat:Connect(function()
script.Parent.CFrame = CFrame.new(script.Parent.Position, A.Position)
local PlayerRay = Ray.new(script.Parent.CFrame.p, (A.CFrame.p - script.Parent.CFrame.p).unit * 500)
local HIT = game.Workspace:FindPartOnRayWithIgnoreList(PlayerRay ,BodyParts)
print(HIT)
end)
end
Problem
local HIT = game.Workspace:FindPartOnRayWithIgnoreList(PlayerRay ,BodyParts)
Everything in the script works correctly, except for this line. The ray does work, but it won't ignore the BodyParts table, if I change "FindPartOnRayWithIgnoreList" with "FindPartOnRay" it will state "Unable to cast value to Object" on the output pointing to the line above. Any idea how to fix this?

1 comment
Sorry, it's still happening but thanks.