Still have questions? Join our Discord server and get real time help.
Log in to vote

How do you use tools to change a part's color when clicked?

Asked by 11 months ago

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

    if  player.Character.PartClicker and then
        part.BrickColor ="Really Red")

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 instead of click detectors Is_Hunter 50 — 11mo

1 answer

Log in to vote
Answered by 11 months ago
Edited 11 months ago

You can use Rays to do it

-- this script is inside the tool
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 ="Really red") -- wich color you want to apply on the part

local function onActivation()
    local Ray =, (Mouse.Hit.p - Tool.Handle.CFrame.p).unit * Distance)
    local Part, Position = workspace:FindPartOnRay(Ray, Character, false, true)
    Part.BrickColor = BrickColor


I hope it helps.

Thanks for the help! It worked! Adv3rtizement 83 — 11mo
Your Welcome^^ Is_Hunter 50 — 11mo

Answer this question