Hello! This is my first time scripting so sorry if this will be obvious So I am trying to make a mining/tycoon hybrid. I got a simple free model mountain (plz no hate), and added some Reddish Brown bricks to it I then added this snippet of code to the bricks that I found online and edited it, so that in theory you would click to mine then the block would turn grey then wait 5 second then it would change back to Reddish brown.
function onClicked(playerWhoClicked) script.Parent.BrickColor = BrickColor.DarkGray() wait(7) script.Parent.BrickColor = BrickColor.Red() end
It, worked, mostly
See wherever I clicked it it turned grey like intended then after five seconds it would turn red not Reddish brown so then I tried this:
function onClicked(playerWhoClicked) script.Parent.BrickColor = BrickColor.DarkGray() wait(7) script.Parent.BrickColor = BrickColor.ReddishBrown() end
It then gave me this error: Workspace.Part.Script:4: attempt to call field 'ReddishBrown' (a nil value) and the block was bright red again! I cannot seem to change this please help!
You use BrickColor.new(string name)
, for example:
BrickColor.new("Reddish brown")
That's the safe way to do it. c: Though he's probably better than me, but here's another way to do it with variables.
local Color = script.Parent.Brickcolor -- this could also work for materials local Material = script.Parent.Material --the function c: --SwardGames, you are many times better than me :p script,Parent.ClickDetector.Mousebutton1Down:connect( function script.Parent.Brickcolor = Brickcolor.new("Really Black") script.Parent.Material = "Neon" wait(1) script.Parent.Brickcolor = Color script.Parent.Material = Material end)
Something like that c: