#how do i make this raycast ignore the tool parts and the player?

1 messages · Page 1 of 1 (latest)

crude kernel
#

i want the raycast to go through (ignore) the player and all parts in the tool
it also doesnt print the parts in the table (v), it just prints b like 30 times

this is a local script in starter player scripts

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local targetPart = workspace:WaitForChild("bullet")
local tyronegun = script.Parent.Parent.Backpack.TyroneGun
local gunevent = game.ReplicatedStorage.fireevent
local gunend = tyronegun.GunEnd
local size
local targethit
local character = player.Character or player.CharacterAdded:Wait()

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
paramtable = {game.Workspace.window, game.Workspace.window2}
for i, v in pairs(tyronegun:GetChildren()) do
if v:IsA("Part") then
table.insert(paramtable, v)
end
end
for i, v in pairs(character:GetChildren()) do
if v:IsA("MeshPart") then
table.insert(paramtable, v)
end
end
print("bvox")
for i, v in pairs(paramtable) do
print("b")
print(v)
end

params.FilterDescendantsInstances = paramtable

local function updatePartOrientation()
local mousePosition = mouse.Hit.Position

targetPart.CFrame = CFrame.lookAt(targetPart.Position, mousePosition)
orientation = targetPart.Orientation
local direction = mousePosition - gunend.Position
raycastResult = workspace:Raycast(gunend.Position, direction, params)
if raycastResult then
    size = raycastResult.Distance
    
end

end

tyronegun.activated:Connect(function()
print("function fired")
print(raycastResult)
gunevent:FireServer(orientation, size)
end)

RunService.RenderStepped:Connect(updatePartOrientation)

little imp
#

to ignore you uh

#

use exclude

#
Raycast Filtering
local Workspace = game:GetService("Workspace")

local rayOrigin = Vector3.zero
local rayDirection = Vector3.new(0, -100, 0)

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true

local raycastResult = Workspace:Raycast(rayOrigin, rayDirection, raycastParams)```
crude kernel
#

moreso this part
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
paramtable = {game.Workspace.window, game.Workspace.window2}
for i, v in pairs(tyronegun:GetChildren()) do
if v:IsA("Part") then
table.insert(paramtable, v)
end
end
for i, v in pairs(character:GetChildren()) do
if v:IsA("MeshPart") then
table.insert(paramtable, v)
end
end
print("bvox")
for i, v in pairs(paramtable) do
print("b")
print(v)
end

params.FilterDescendantsInstances = paramtable

little imp
#

uh

#

something with the tool reference probably

#

I'd suggest to just

#

using collectionservice

#

and tagging everything you want to exclude with a tag "EXCLUDE"

#

then use collectionservice:gettagged to reference all parts w it