Well.
I'm not sure if that's even Lua, but let's get on with it:
There's a property of parts called Touched. You want to change the color of the part, so first you'll need to hook up a function to fire when the part is touched. How would we do that? Like this
script.Parent.Touched:connect(function()
end)
Good, so now we have that. Now, to changed color, there is another property that changes the color of something; it's called BrickColor. To change this property with a script, we would do this:
game.Workspace.Part.BrickColor = BrickColor.new("Bright red")
So, what can we do with the two things that we just learned? We can hook up the event to change the brick color based on what the brickcolor already is, like so:
script.Parent.Touched:connect(function()
if script.Parent.BrickColor == "Black" then
script.Parent.BrickColor = BrickColor.new("White")
end
if script.Parent.BrickColor == "White" then
script.Parent.BrickColor = BrickColor.new("Black")
end
end)
On a final note, you should always check the wiki for a tutorial. I know there's one on the wiki having to do something with this.
Hope this helps.
1 comment
Edit your post to use the Lua code formatting block. Select your code and press the Lua button. A line of ~~~ should appear before and after the code.