This property can only be read from. Attempting to write to it will cause an error.
This item is not replicated across Roblox’s server/client boundary.
The object in 3D space the
Mouse|mouse is pointing to.
Mouse/TargetFilterhas 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
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)