First of all, think basic. There is a position a part has, and there is a position Mouse has. In any other conditions, if X's absolute value is bigger than Y and Z's absolute values, it means Mouse is at right surface or left surface of part. Then, if X is negative, it's left, if X is positive, it's right. So if there is non-rotated part and a Mouse touching to the part:
02 | if math.abs(X) > math.abs(Y) and math.abs(X) > math.abs(Z) then |
08 | elseif math.abs(Y) > math.abs(X) and math.abs(Y) > math.abs(Z) then |
14 | elseif math.abs(Z) > math.abs(X) and math.abs(Z) > math.abs(Y) then |
Now, let's say part is rotated. It looks much harder now, right? Yep, it is. But we can cheat to make it easier :)
Let's say there is a rotated part, so we will need basic CFrame info, and some other basic info about model's primary part speciality.
01 | model = Instance.new( "Model" ) |
02 | model.Name = "SurfaceFinder" |
03 | MP = Player.Character.Humanoid.TargetPoint |
08 | Part 2 = Instance.new( "Part" ) |
11 | model.PrimaryPart = Part 1 |
12 | model:SetPrimaryPartCFrame(CFrame.new(PP.X,PP,Y,PP,Z)*CFrame.Angles( 0 , 0 , 0 )) |
After doing this, you need to use which surface of Part2 touching at Part1
IMPORTANT NOTE: You have to change the script at first code block to make it work with part's size, otherwise it will tell you wrong surface of the part.