|
| 12 Jul 2015 12:24 PM |
I've been trying to make a script that changes the brick colour and material of a union when it's clicked.
This is what it looks like so far.
Union >ClickDetector >Script
Script: function onClicked(Union) if script.Parent.BrickColor == "Dark stone grey" then script.Parent.BrickColor = "Pastel blue-green" script.Parent.Material = "Neon" else script.Parent.BrickColor = "Dark stone grey" script.Parent.Material = "Marble" end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
I'm not fluent in Lua, so sorry if the issue is a little obvious. I mainly work in Python.
Seɴpαι нαѕ ɴoтιced yoυ ✔ |
|
|
| Report Abuse |
|
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 12 Jul 2015 12:33 PM |
Is it not functional or something?
ᴍʏ ɴɪɢᴀ ғʀᴏᴍ ᴀɴᴏᴛʜᴇʀ ᴡɪɢᴀ |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2015 12:41 PM |
Nah, it comes up with the hand-cursor but absolutely nothing happens when I click.
Seɴpαι нαѕ ɴoтιced yoυ ✔ |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2015 12:44 PM |
function onClicked(Union) if script.Parent.BrickColor == BrickColor.new("Dark stone grey") then script.Parent.BrickColor = BrickColor.new("Pastel blue-green") script.Parent.Material = "Neon" else script.Parent.BrickColor = BrickColor.new("Dark stone grey") script.Parent.Material = "Marble" end end script.Parent.ClickDetector.MouseClick:connect(onClicked) |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2015 12:44 PM |
| You need to do BrickColor.new |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 12 Jul 2015 01:00 PM |
BrickColors are userdatas, it is not exactly good for memory to create a new userdata every time you need one.
So you create a variable for each color you want that is equal to the BrickColor userdata you want.
Like this:
Bright_blue = BrickColor.new("Bright blue")
Part.BrickColor = Bright_blue |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2015 01:32 PM |
Thanks, Jiggly and Chim! I got the brick colour to change. However, it turns from blue to grey but not from grey to blue. Is there anything else I'm doing wrong?
Seɴpαι нαѕ ɴoтιced yoυ ✔ |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2015 02:05 PM |
Anyone? I've been trying for a while now, but no matter what I try, it always works one way around but not the other. Have I done the if/else statement wrong?
Seɴpαι нαѕ ɴoтιced yoυ ✔ |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 12 Jul 2015 03:53 PM |
--I'm on my phone so this isn't easy for me.
local Blue = BrickColor.new("Pastel blue green") local Grey = BrickColor.new("Dark stone grey")
local Neon = Enum.Material.Neon local Marble = Enum.Material.Marble
script.Parent:WaitForChild("ClickDetector").MouseClick:connect(function() script.Parent.BrickColor = (script.Parent.BrickColor == Blue and Grey or Blue) -- Lua's and/or logic at work script.Parent.Material = (script.Parent.BrickColor == Blue and Neon or Marble) end)
-- This should work but like I said I wrote it on my phone so there could be errors. |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2015 04:03 PM |
as jiggly said, you need brickcolor.new()
if b.BrickColor == BrickColor.new("Dark stone grey") then print("it's fark cave something") end |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 12 Jul 2015 04:14 PM |
@hunxrepair
Have you read any of the thread? We are WAY past that. |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2015 09:46 PM |
| It is changing colors, the neon just makes it so bright you can't notice. Click the block to make it change to neon, then check its properties. I've tested it. |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2015 10:43 AM |
Oh wow, thanks Chim! That works perfectly.
Sorry if it was a little obvious. I haven't taken any proper Lua courses .-.' I'll see if I can find a decent one when I'm finished with my HTML and JavaScript ones.
Seɴpαι нαѕ ɴoтιced yoυ ✔ |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
| |
|