Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to get the specific side of a part?

Asked by 7 years ago
Edited 7 years ago

I'm creating a program where you need to know which side of the part is clicked, to determine the orientation of an object that will be attached to the part. The rest I can take care of, but I'm not sure how to get the exact side of the part (i.e, TopSurface, RightSurface, LeftSurface, etc - but with position).

The code itself should print the side of the part that was clicked with the user's mouse, but I have no idea how I'd go about doing this. Here is how I planned on it looking:

local PlayerService = game:GetService'Players'
local Player = PlayerService.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:connect(function()
    local Target = Mouse.Target

    if Target and Target:IsA("BasePart") then
        local MousePos = Mouse.Hit.p
        local PartSide -- Where it calculates the side of the part that's clicked

        print(PartSide) -- Print the position, string, or anything that represents the side of the part that was clicked.
    end
end)

If anyone has any insight on how I could go about solving this, it'd be much appreciated!

1 answer

Log in to vote
0
Answered by 7 years ago

All you needed to do was just do Mouse.TargetSurface I made my own building system and at first needed to know the Target Sides then I find that Roblox had a way to get what side the Target is.

Here is the Wiki for Mouse

local PlayerService = game:GetService'Players'
local Player = PlayerService.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:connect(function()
    local Target = Mouse.Target
    if Target and Target:IsA("BasePart") then
        local MousePos = Mouse.Hit.p
        local PartSide = Mouse.TargetSurface -- Where it calculates the side of the part that's clicked
        -- To check what it equals then do PartSide == Enum.NormalId.Front
        print(PartSide) -- Print the position, string, or anything that represents the side of the part that was clicked.
    end
end)

0
Wow, looked at the wiki page before and I was completely blind to that. Thank you. MightyQuestionAsker 297 — 7y
0
Your Welcome. xxmobkiller 5 — 7y
Ad

Answer this question