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)
You can't with position however you can with CFrame. Don't ask me how though, I am not quite that advanced in math. The standard Vector3 value that you use with CFrame.new() is a tip of the ice berg. CFrame can also give current rotation as well as it's position. I would look it up on the wiki as it explains the rotation matrix a bit more.