Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help me make a paint colour change script?

I have been trying to make a game where you can click on a square to paint (pixel art) currently I wanted to make a script where you click on a brick which changes the colour of your "paint".

For the actual drawing script without the colour change, I wrote this:

local part = script.Parent
local clickDetector = script.Parent.ClickDetector

clickDetector.MouseClick:Connect(function()
	part.BrickColor = BrickColor.new("Black")
end)

clickDetector.RightMouseClick:Connect(function()
	part.BrickColor = BrickColor.new("White")
end)

This script only changes the colour of the tile that you click on, and it is only able to paint in one colour. I tried to figure out how to do the colour change script. So I added a part that you click on to change the colour of the paint. I put in a click detector and i added the change colour part into the painting script. Can someone tell me if this is correct? And if it isn't, please help.

local part = script.Parent
local clickDetector = script.Parent.ClickDetector
local changeColour = script.Parent.Parent.changeColourBlue.ClickDetector

changeColour.MouseClick:Connect(function()
	clickDetector.MouseClick:Connect(function()
		part.BrickColor = BrickColor.new("Blue")
	end)
	clickDetector.RightMouseClick:Connect(function()
		part.BrickColor = BrickColor.new("White")
	end)
end)

I will appriciate it if someone helped me. <3

1 answer

Hi realKazYT, here's my solution.

Add two brick color values into the drawing script. Name the first one "EraseColor" and the second one "DrawColor", then we will start coding.

local part = script.Parent
local eraseColor = script.EraseColor.Value
local drawColor = script.DrawColor.Value -- Getting the values of each brickcolor
local clickDetector = script.Parent.ClickDetector

clickDetector.MouseClick:Connect(function()
    part.BrickColor = BrickColor.new(drawColor) -- I am assuming this is to draw
end)

clickDetector.RightMouseClick:Connect(function()
    part.BrickColor = BrickColor.new(eraseColor) -- I am assuming this is to erase
end)

Now for the color changing script.

local part = script.Parent
local clickDetector = script.Parent.ClickDetector
local changeColour = script.Parent.Parent.changeColourBlue.ClickDetector

changeColour.MouseClick:Connect(function()
	local eraseColor = (Wherever the drawing script is).EraseColor -- Getting both values
	local drawColor = (Wherever the drawing script is).DrawColor
	drawColor.Value = BrickColor.new(Color goes here) -- Setting values to new ones
	eraseColor.Value = BrickColor.new(Color goes here)
	-- Now once a player starts drawing it will use the color set here
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.