Trying to check if wall is infront of player

I want to be able to check if a wall is infront of my player, the wall being a part within PlayersInterior.Build.InteriorElements and I use FindPartOnRayWithWhitelist so it’s only checking for parts within a certain folder (where the walls are stored) however, it always returns nil, no matter what way my player is facing

local CheckRay = Ray.new(Player.Character.HumanoidRootPart.CFrame.p, Vector3.new(0, 0, 5))
local part = workspace:FindPartOnRayWithWhitelist(CheckRay, {PlayersInterior.Build.InteriorElements})
print(part)

Note again, I have tried with my character facing the wall, back against the wall, and both arms against the wall, always nil. What am I missing?

2 Likes

Try checking this link out.

I’m pretty sure your answer is gonna be there, I read it and understood some of it and then found out that you can use it to your advantage.

You can edit the script found in that website to give you this ( not my script, I just derived this using the example, all credits go to @Eternalove_fan32 )

local Player = game.Players[PlayerName]
local HRP = Player.Character.HumanoidRootPart
local Lenght = 15
local Ray = Ray.new(HRP.Position, HRP.CFrame.LookVector*Lenght)
local Wall, HitPosition, Normal, Material = workspace:FindPartOnRay(Ray, Player.Character)
if Wall then -- If wall is in front of you
    print("wall in front of you")
else -- if theres no wall
    print("wall not in front of you")
end

edit: I tried the script on studio and it worked fine.

1 Like

What does ‘AI’ mean in this?

local Wall, HitPosition, Normal, Material = workspace:FindPartOnRay(Ray, AI)

Figured it out, but problem

It picks up invisible parts too. I want it to only pick up only a few select parts within a folder

1 Like

My bad, it was meant to be Player.Character instead of AI.

1 Like

Probably a long shot but try this script out, maybe it might solve it? This is like my second time working with rays so I’m sorry if it doesn’t work.

local Player = game.Players[PlayerName]
local HRP = Player.Character.HumanoidRootPart
local Lenght = 15
local Ray = Ray.new(HRP.Position, HRP.CFrame.LookVector*Lenght)
local Wall, HitPosition, Normal, Material = workspace:FindPartOnRayWithWhitelist(Ray, {PlayersInterior.Build.InteriorElements})
if Wall then -- If wall is in front of you
    print("wall in front of you")
else -- if theres no wall
    print("wall not in front of you")
end
5 Likes