Alright, So apparently I'm supposed to get the direction of a part then find part on ray, but how am I getting the direction of a part with position?
'Players.Player.Backpack.LocalScript:21: attempt to index field '?' (a nil value)'
local walls = game.Workspace.Walls:GetChildren()
local chartorso = game.Players.LocalPlayer.Character.Torso
local lowname = nil
local lowest = 20
for i = 1, #walls do
walls[i].Name = "Wall"..i
end
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
for i,v in pairs (walls) do
if math.ceil((chartorso.Position-v.Position).magnitude) < lowest then
lowest = math.ceil((chartorso.Position-v.Position).magnitude)
lowname = v.Name
end
end
print(lowname)
print(chartorso.Position)
local ray = Ray.new(chartorso.Position, walls[lowname].Position * 300)
local hit, position = game.Workspace:FindPartOnRay(ray)
for i = 1, #walls do
walls[i].BrickColor = BrickColor.new("Smoky grey")
end
game.Workspace.Walls[lowname].BrickColor = BrickColor.Green()
lowest = 20
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

2 comments
I think I misunderstood you question. You are looking for how to get the direction of a part compared to the position of another object aren't you.
ye