So I’ve been working on this custom interaction system, it’s working fine but I’ve got an issue when I’ve tried to implement a feature that detects if the player can see the interactable (the interactable instance), I’m confused why this isn’t working because I used to do these kind of stuffs alot, here’s my current code:
function RaycastInter(interactable)
print("RAYCAST")
local ignoreList = {}
for i, v in pairs(Player.Character:GetDescendants()) do
if v:IsA("BasePart") then
table.insert(ignoreList, v)
end
end
for i, v in pairs(workspace:GetDescendants()) do
if v:IsA("BasePart") and v.Transparency == 1 or v.Name == "Laser" then
table.insert(ignoreList, v)
end
end
for i, v in pairs(interactable:GetDescendants()) do
if v:IsA("BasePart") then
table.insert(ignoreList, v)
end
end
local RP = RaycastParams.new()
RP.FilterDescendantsInstances = ignoreList
RP.FilterType = Enum.RaycastFilterType.Blacklist
local origin = Char.HumanoidRootPart.Position
local target = interactable
local direction = (target.Position - origin).unit * 10000
local results = workspace:Raycast(origin, direction, RP)
local laserPart = Instance.new("Part")
laserPart.Anchored = true
laserPart.Name = "Laser"
laserPart.BrickColor = BrickColor.new("Really red")
laserPart.CanCollide = false
laserPart.Size = Vector3.new(0.2, 0.2, (origin - target.Position).Magnitude)
laserPart.CFrame = CFrame.new(origin, target.Position) * CFrame.new(0, 0, -(origin - target.Position).Magnitude / 2)
laserPart.Parent = workspace
print(results)
if not results then
return true
end
end
function Trigger(interactable)
for i, v in pairs(interactable:GetChildren()) do
if v:IsA("RemoteEvent") and v:FindFirstChild("IsInteractEvent") then
if v:FindFirstChild("IsInteractEvent").Value == true then
local dist = (interactable.Position - Char.HumanoidRootPart.Position).Magnitude
if RaycastInter(interactable) then
if dist < InteractionStats.Range then
v:FireServer()
PlayAnim(currentUI, "Interact")
end
end
end
end
end
end
Here’s the video:
(The laser part is used just to visualize raycast)