TargetSurface and how to use it

Hello, I’m somewhat new to scripting and I’m using the local player’s mouse and “TargetSurface” to detect what SIDE of a part I am clicking, and when I print said side, I see it in the output as Front, Back, Right, ect ect. But how can I use TargetSurface to run a function that happens when I click the front, like lets say I click the front and a part turns red, i click the top and a part turns black, that kind of thing. Does anybody know how I can just catch and use a part’s side via TargetSurface?

If you took the time to read this and even care to the slightest, thank you for your time and any help means the world to me.

1 Like

LocalScript in StarterCharacterScripts:

task.wait(2)
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local Part = workspace.Part

local Surfaces = {
	[Enum.NormalId.Front] = Color3.fromRGB(255, 0, 0), 
	[Enum.NormalId.Back] = Color3.fromRGB(255, 255, 0),
	[Enum.NormalId.Top] = Color3.fromRGB(0, 255, 0),
	[Enum.NormalId.Bottom] = Color3.fromRGB(0, 0, 255), 
	[Enum.NormalId.Right] = Color3.fromRGB(255, 0, 255),
	[Enum.NormalId.Left] = Color3.fromRGB(0, 255, 255)
}

Mouse.Button1Down:Connect(function()
	Part.Color = Surfaces[Mouse.TargetSurface]
end)
1 Like

Thank you, means a lot that you wrote this for me. Also helped me understand this more than I did before. :pray:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.