I'm trying to do something when someone comes into the view of a player. I was given to use GetPartsObscuringTarget and WorldToScreenPoint together, but it's not working.
EDIT: This has been an issue for the past 3 days so I really need help.
This is how much I have so far:
game:GetService("RunService").RenderStepped:connect(function() local function XRay(castPoints, ignoreList) ignoreList = ignoreList or {} local parts = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints, ignoreList) for _, part in pairs(parts) do part.LocalTransparencyModifier = 0.75 for _, child in pairs(part:GetChildren()) do if child:IsA("Decal") or child:IsA("Texture") then child.LocalTransparencyModifier = 0.75 end end end end end)
Hello again Sir. I'm from your other Question. I think I am the only person who has accomplished this?
It looks like you're trying to accomplish an X-Ray with GetPartsObscuringTarget but your problem is that the Event, RenderStepped is constantly creating a Function but nothing is calling the Function.
Your goal is to detect a player physically in view.
Use RunService to make a Loop. In that loop. First, use WorldToScreenPart to check if player is Visible. If Player is Visible is True then. Use GetPartsObscuringTarget to check if there are no parts blocking your view from the Player. Then if the check is passed then Player is Physically in view.
This Script Should Print Every Part And MeshPart Physically In View:
game:GetService("RunService").Heartbeat:Connect(function() for _,object in pairs(workspace:GetDescendants()) do if object:IsA("Part") or object:IsA("MeshPart") then if not object:IsDescendantOf(game.Players.LocalPlayer.Character) then local object2,visible = workspace.CurrentCamera:WorldToScreenPoint(object.Position) if visible == true then local pos1 = workspace.CurrentCamera.CFrame.Position local pos2 = object.Position local castPoints = {pos1,pos2} local ignoreList = {game.Players.LocalPlayer.Character, object} local obstructs = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints,ignoreList) if obstructs[1] then return elseif not obstructs[1] then print(object.Name .. " Has Been Detected") end elseif visible ~= true then return end end end end end)