Hello DevForums! I wanted to learn how to use this in my own game, so I decided to use the example code that comes with the article to test it out.
Code:
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
I put this in a localscript which is parented to the player gui, but it doesn’t work. I tried putting it in the starterpack also, but it still doesn’t work. I was wondering if anyone had an idea to why it doesn’t work.
Should the “What the camera is looking at” be the path to the part the camera should be focused on like the humanoid root part? Also, the camera position should just be a new vector3 , right? I am particularly confused on the “PositionFarAwayOnTheDirectionOfWhereTheFunctionShouldLookForParts” meant.
local function XRay(castPoints, ignoreList)
local castPoints = {game.Workspace.CurrentCamera.CFrame.Position, game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")}
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
Edit: To be clear, where would this go? The starterpack or the startergui?
local function XRay(castPoints, ignoreList)
local castPoints = {game.Workspace.CurrentCamera.CFrame.Position, game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position} -- Added .Position
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