Telasim0
|
  |
| Joined: 10 Jun 2011 |
| Total Posts: 2263 |
|
|
| 03 Apr 2017 03:34 PM |
I made another post, but I'm just gonna ignore that. I'm expierementing with functions and I'm trying to make a script where when a player clicks the part, it changes the color. Here is the script
Instance.new("ClickDetector", script.Parent) s = script.Parent.Part
function onClick() s.BrickColor = BrickColor.new ("Really red") end
s.ClickDetector.MouseClick:connect(onClick)
I know am noob |
|
|
| Report Abuse |
|
|
| |
|
Telasim0
|
  |
| Joined: 10 Jun 2011 |
| Total Posts: 2263 |
|
| |
|
|
| 03 Apr 2017 03:35 PM |
You're parenting the ClickDetector to `script.Parent` but giving `script.Parent.Part` the reference of `s`. Then you're trying to access a ClickDetector inside `s`.
|
|
|
| Report Abuse |
|
|
Telasim0
|
  |
| Joined: 10 Jun 2011 |
| Total Posts: 2263 |
|
|
| 03 Apr 2017 03:35 PM |
| But wait, How would I repeat this? Like, when you click again, it turns to medium stone grey? |
|
|
| Report Abuse |
|
|
|
| 03 Apr 2017 03:39 PM |
use arrays or if statements
local colors = { BrickColor.new( "Really red" ); BrickColor.new( "Medium stone grey" ); } local color = 1 local function onClick() s.BrickColor = colors[ color ] color = color % #colors + 1 --% is modulus / mod, just makes it return to 0 when it overflows because of remainder division end
if statement:
local on = false local function onClick() on = not on if on then s.BrickColor = BrickColor.new( "Really red" ) else s.BrickColor = BrickColor.new( "Medium stone grey" ) end --you can also just do --s.BrickColor = on and BrickColor.new( "Really red" ) or BrickColor.new( "Medium stone grey" ) end |
|
|
| Report Abuse |
|
|
Telasim0
|
  |
| Joined: 10 Jun 2011 |
| Total Posts: 2263 |
|
| |
|