PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

Target

Mouse

BasePart

The object in 3D space the mouse is pointing to.

If Mouse/TargetFilter has been set, the target filter and its descendants will be ignored.

When the mouse is not pointing at a BasePart, for example when it is pointing at the sky, Target will be nil.

Developers looking for the position of the mouse in 3D space should use Mouse/Hit.


Code Samples


Color Randomizer Tool

The following code sample, when placed in StarterPlayerScripts will create a tool in the player’s backpack that, once equipped, will change the BasePart/BrickColor of every BasePart the player clicks on.

local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer
local backpack = localPlayer:WaitForChild("Backpack")

local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.CanBeDropped = false 
tool.Parent = backpack

tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if mouse.Target and mouse.Target.Parent then
			mouse.Target.BrickColor = BrickColor.Random()
		end
	end)
end)