Help needed with part on screen

  1. What do you want to achieve?
    Learning something about checking if something’s on your screen.
  2. What is the issue?
    I want to know if you can detect that if behind something
  3. What solutions have you tried so far?
    Looking it up, found nothing

Basically, i want a localscript to check if a part is visible on screen even behind specific parts with a specific name.
This is what i use right now:

local _, withinScreenBounds = workspace.CurrentCamera:WorldToViewportPoint(v.Position)
		
	if withinScreenBounds then
		local ray = Ray.new(workspace.CurrentCamera.CFrame.Position,(v.CFrame.Position - workspace.CurrentCamera.CFrame.Position))
		local Part = workspace:FindPartOnRay(ray,game:GetService("Players").LocalPlayer.Character)
if Part == v then

So to clarify, you just need the ray to ignore specific parts with a certain name?

True, i want to make it so that it doesn’t ignore walls and stuff (which already works). But should ignore a specific part(s) yeah.

Use workspace:Raycast()
Make a raycastparameter, make it’s type blacklist and then pick all parts with a given name and insert them in a table and make the raycastparameter.filterdescendantinstances = the table

You might look into using collision groups. If you add the ignored parts to a certain collision group, you can add that collision group to the RaycastParams and the ray will go through them. If that won’t work in your scenario, let me know and I’ll throw a function your way. RaycastParams would be cleaner and more efficient though.

@JarodOfOrbiter @raposaninjagamesxl
Any chance one of u can show me an example of a localscript for that?

I don’t know much about raycast and stuff lol

``
local _, withinScreenBounds = workspace.CurrentCamera:WorldToViewportPoint(v.Position)

if withinScreenBounds then
	local ray = Ray.new(workspace.CurrentCamera.CFrame.Position,(v.CFrame.Position - workspace.CurrentCamera.CFrame.Position))

local param = Raycastparameter.new()
param.filtertype= Enum.raycastfiltertype.blacklist
local ignoretable = {}
local descendants = Workspace:GetDescendants()
for i = 0, #descendants do
if i:IsA(“BasePart”) and I.Name == “insertnamehere” then
table.insert(ignoretable,i)
end
end
param.filterdescendantsinstance = ignoretable
local Part = workspace:Raycast(startposition,endposition,param)
if Part.Instance == v then
end
``
I wrotr this using my phone, expect grammar errors

I hope it helps you, sorry for grammar errors

Yo thanks i will try it out in a few hours since i got to go now. Once it works i wil tell u!

Sure! The first difference is that instead of FindPartOnRay, you’ll want to use the new Raycast method. Let me know if this doesn’t work, I’ve never used the new Raycast method and I’ve never used collision groups.

There are a few variables you’ll need to rename or crate (camera_pos, target_pos, target_part), and you’ll need to add all of the ignored objects to a collision group called “InvisibleToRaycast”

-- Check first if the part is on screen.

local params = RaycastParams.new() -- https://create.roblox.com/docs/reference/engine/datatypes/RaycastParams
params.FilterType = Enum.RaycastFilterType.Blacklist -- Specify that we want to filter out certain parts
params.FilterDescendantsInstances = {} -- Add any extra parts you want to filter out here
params.IgnoreWater = false -- Whether or not to ignore water
params.CollisionGroup = "InvisibleToRaycast" -- The collision group to ignore

local result = workspace:Raycast(camera_pos, target_pos-camera_pos, params) -- Raycast with the new method.

if result then -- If we hit something
    if result.Instance == target_part then -- If we hit the target part
        print("Target is visible!")
    end
end

@JarodOfOrbiter @raposaninjagamesxl
Sorry for not being here for a day. To be more specific i want it to ignore a player’s character. How should that be done?

That’s all you want it to ignore? Use your original code, but add the player’s character to the call:
FindPartOnRay(yourRay, character)

Yo thank u for all ur help.
My goal was to make it so that a part is detected on screen even behind any player’s character basically.
I found out how and got it to work!
I appreciate ur help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.