Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a tool detect what brick I have clicked on?

Asked by 6 years ago

How do I use mouse.Target to set the brick that I click?

like

'when player clicks'

brick = mouse.Target

or something like this.

0
make a attempt before asking User#23365 30 — 6y
0
Is this something like what you wanted? https://i.gyazo.com/772bedded48be852799846d62aed7a5e.gif aazkao 787 — 6y
0
@EXpodo1234ALT I did make an attempt but it failed, this is why im asking. Im not sure what you want devisings 58 — 6y
0
i think he wants something involving magnitude and maybe transparency tweening theking48989987 2147 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Answer this question