Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

2 comments

0

Wow, looked at the wiki page before and I was completely blind to that. Thank you.

0

Your Welcome.

This discussion is preserved as it was. New answers, comments, and votes are closed.