So I got this piece of code right over here, and it looks like this:
local Player = game.Players.LocalPlayer
local HRP = Player.Character.HumanoidRootPart
local Length = 15
local Ray = Ray.new(HRP.Position, HRP.CFrame.LookVector * Length)
local Wall, HitPosition, Normal, Material = workspace:FindPartOnRay(Ray, Player.Character)
if Wall then
print("wall in front of you")
end
It prints if you spawn right next to a wall, however it doesn’t wait until you touch a wall, and that’s my goal, so how can I accomplish this? Here is what I tried:
repeat
wait(1)
until Wall
print("wall in front of you")
You are checking whether the wall exists outside of the repeat loop so it’ll never change since it’s defined once when the script begins and never again.
I made a slight mistake. There are two parts to your raycast.
Please try this code
local HRP = Player.Character.HumanoidRootPart
local Length = 15
local Ray = Ray.new(HRP.Position, HRP.CFrame.LookVector * Length)
local Wall, HitPosition, Normal, Material = workspace:FindPartOnRay(Ray, Player.Character)
repeat
wait(1)
Ray = Ray.new(HRP.Position, HRP.CFrame.LookVector * Length)
Wall, HitPosition, Normal, Material = workspace:FindPartOnRay(Ray, Player.Character)
until Wall
print("wall in front of you")
Ray might not be the best name for your variable.
Let’s fix that:
local HRP = Player.Character.HumanoidRootPart
local Length = 15
local WallRay = Ray.new(HRP.Position, HRP.CFrame.LookVector * Length)
local Wall, HitPosition, Normal, Material = workspace:FindPartOnRay(WallRay, Player.Character)
repeat
wait(1)
WallRay = Ray.new(HRP.Position, HRP.CFrame.LookVector * Length)
Wall, HitPosition, Normal, Material = workspace:FindPartOnRay(WallRay, Player.Character)
until Wall
print("wall in front of you")