I have made a click detector and coded a script that will change the part's color when it is clicked but now I want to make it only turn that color when the player clicks on the brick with a certain tool.
clickDec = script.Parent.ClickDetector part = script.Parent clickDec.MouseClick:connect(function(player) if player.Character.PartClicker and then part.BrickColor = BrickColor.new("Really Red") end end)
The MouseClick event doesn't even get called when they are holding the tool and it shows I can click on the part when I'm not holding a tool but when I am it doesn't.
Does anyone know how to make it so the tool can execute an event when it clicks on the part?
You can use Rays to do it
-- this script is inside the tool -- LOCALSCRIPT local Tool = script.Parent local Players = game:GetService"Players" local Player = Players.LocalPlayer local Mouse = Player:GetMouse() local Character = Player.Character or Player.CharacterAdded:Wait() local Distance = 300 -- a distance from where you can change the part's color local BrickColor = BrickColor.new("Really red") -- wich color you want to apply on the part local function onActivation() local Ray = Ray.new(tool.Handle.CFrame.p, (Mouse.Hit.p - Tool.Handle.CFrame.p).unit * Distance) local Part, Position = workspace:FindPartOnRay(Ray, Character, false, true) Part.BrickColor = BrickColor end Tool.Activated:connect(onActivation)
I hope it helps.