generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Game Design
Home Search
 

Re: Trying to get a script to change material/colour

Previous Thread :: Next Thread 
Senpaisaur is not online. Senpaisaur
Joined: 25 Apr 2015
Total Posts: 1856
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 is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
12 Jul 2015 12:33 PM
Is it not functional or something?

ᴍʏ ɴɪɢᴀ ғʀᴏᴍ ᴀɴᴏᴛʜᴇʀ ᴡɪɢᴀ
Report Abuse
Senpaisaur is not online. Senpaisaur
Joined: 25 Apr 2015
Total Posts: 1856
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
JigglyWiggles is not online. JigglyWiggles
Joined: 16 Jun 2012
Total Posts: 223
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
JigglyWiggles is not online. JigglyWiggles
Joined: 16 Jun 2012
Total Posts: 223
12 Jul 2015 12:44 PM
You need to do BrickColor.new
Report Abuse
chimmihc is not online. 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
Senpaisaur is not online. Senpaisaur
Joined: 25 Apr 2015
Total Posts: 1856
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
Senpaisaur is not online. Senpaisaur
Joined: 25 Apr 2015
Total Posts: 1856
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 is not online. 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
hunxrepair is not online. hunxrepair
Joined: 07 Aug 2011
Total Posts: 777
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 is not online. 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
JigglyWiggles is not online. JigglyWiggles
Joined: 16 Jun 2012
Total Posts: 223
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
Senpaisaur is not online. Senpaisaur
Joined: 25 Apr 2015
Total Posts: 1856
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 is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
13 Jul 2015 11:09 AM
Alrighty
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image