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

How do i make a brick change colour?

local brick = Workspace.Brick 
 
function onTouch(part) 
	brick.Transparency = 1
	wait(1) 
	brick.Transparency = 0 
end 
 
brick.Touched:connect(onTouch)

What am i doing wrong? and what do i do to make it work?

3 comments

0

I am also very. VERY new to scripting.

0

You're changing the Transparency, which is totally different from changing a brick's BrickColor. http://wiki.roblox.com/index.php?title=API:Class/BasePart/Transparency http://wiki.roblox.com/index.php?title=API:Class/BasePart/BrickColor

6 answers

local brick = Workspace.Brick

function onTouch(part) 
    brick.Transparency = 1 -- You're changing the transparency of the brick, which is different from 
changing the color of the brick.
    brick.Color = BrickColor.new("Bright red")  -- Using this will change the brickcolor. If you would like to learn more about these things, please reference these links (after script)
    wait(1) 
    brick.Transparency = 0 
end 

brick.Touched:connect(onTouch)

http://wiki.roblox.com/index.php?title=API:Class/BasePart/Transparency http://wiki.roblox.com/index.php?title=API:BrickColor

BrickColor doesn't go by numbers, it's by its name in Explorer. For example, there is a color called "Really red", if you want a brick to be red, you would input this script:

game.Workspace.BrickNameHere.BrickColor = BrickColor.new("Really red") 

When inputted, the brick will turn red. Just highlight the color in paint bucket with your mouse and it will tell you what to put in the strings, or quotation marks "".

If you want to make your script example bright blue, you would do the following:

local brick = Workspace.Brick
 
function onTouch(part)
brick.BrickColor = BrickColor.new("Bright blue") 
end
brick.Touched:connect(onTouch)

What you did is Transparency, which basically determines whether the brick is opaque, or clear like a window.

Alright, so you are accessing the Transparency, not BrickColor. Here's how it should be:

brick = game.Workspace.Part
function onTouch()
	brick.BrickColor = BrickColor.new("Lime green") --You have to spell it correctly.
end
brick.Touched:connect(onTouch)

You gotta be careful with the capitals... Here's how it should NOT be:

brick = game.Workspace.Part
function onTouch()
	brick.BrickColor = BrickColor.new("Lime Green")
end
brick.Touched:connect(onTouch)

That would display an error because the correct color is Lime green, not Lime Green. And if you want it to go back to a certain color(We will use Medium stone grey as an example) use this:

brick = game.Workspace.Part
function onTouch()
	brick.BrickColor = BrickColor.new("Lime green")
	wait(1) -- This can be any number that you want*.
	brick.BrickColor = BrickColor.new("Medium stone grey")
end
brick.Touched:connect(onTouch)
--* = Remember that the script will wait for the number that you set it to before setting the color to medium stone grey

Oh and also, brick = game.Workspace.Brick is incorrect unless you renamed the part into Brick. PS: You gotta put the script INSIDE the part.

local brick = workspace.Brick

function onTouched()
	brick.Transparency = 1
	wait(1)
	brick.Transparency = 0
	brick.BrickColor = BrickColor.new('Really red')
end

brick.Touched:Connect(onTouched)

I used a variable to hold the amount of time you want to wait, so that you don't have to look for the line that the wait function is on. :)

local brick = workspace.Brick
local timetowait = 1
function ontouch(part)
	brick.Transparency = 1
	brick.BrickColor = BrickColor.new("Blue") -- You can change the color to what ever you want.
	wait(timetowait)
	brick.Transparency = 0
end
local brick = workspace.Brick

script.Parent.Touched:connect(function(part)
brick.Transparency = 1
brick.Color = Color3.new(math.random())
wait(1)
brick.Transparency = 0

end)

Accept Answer Please

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