How do I use mouse.Target to set the brick that I click?
like
'when player clicks'
brick = mouse.Target
or something like this.
so first, in a local script establish some variables also, create a remote event and put it inside the replicated storage
--put this in the tool local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local tool = script.Parent local event = game.ReplicatedStorage.RemoteEvent
then after establishing the variables, you need an event when the tool is clicked, luckily there is already and event for that, it is the Activated event
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local tool = script.Parent local event = game.ReplicatedStorage.RemoteEvent tool.Activated:Connect(function() local target = Mouse.Target if target then end end)
if you want to modify the properties of that part then you need the remote event.
--local local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local tool = script.Parent local event = game.ReplicatedStorage.RemoteEvent tool.Activated:Connect(function() local target = Mouse.Target if target then event:FireServer("ChangeProperties",target) end end) --server local event = game.ReplicatedStorage.RemoteEvent event.OnServerEvent:Connect(function(plr,message,target) if message == "ChageProperties" and target then --example changes --[[target.Color = Color3.new(0,1,0.5) target.Transparency = 0.25 target.Orientation = Vector3.new(90,84,2) target.Size = Vector3.new(2,2,2)]] end end)
Reminder that this is basic stuff! If you don't want to try this, then go on with theking48989987's answer!
Put a tool inside, and uncheck it's ReqiresHandle
checkbox. It should be somewhere inside StarterPack.
After that's done, add a LocalScript
inside it. There should be some code like this:
local mouse = game.Players.LocalPlayer:GetMouse() local player = game.Players.LocalPlayer script.Parent.Activated:Connect(function () local target = mouse.Target if target then print(player.Name .. " targeted " .. target.Name .. "!") end end)
This line of code is simple and basic to go through.
First, Line 1 and 2 declare the local player and it's mouse. (their client)
Beginning of the third line connects an event listener.
The lines of code after that declare a variable, which can be used to know which part the Mouse
is targeting, so it goes through a check, if the mouse's Target
exists. If we didn't add that if condition, we would get an error while printing this through the console output.
This is pretty much most of the basic stuff this sample of code can do. and when you click a part, it will print it to the Output. (can be turned on in the View tab)
There's also dot notation in one line of the code sample. This is an efficient way of getting to print multiple declared strings at one line to the Console.
The console is very useful and powerful when debugging, and is a great need.
If you don't get what you expected, you'll have some errors.