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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

NEED HELP WITH NOOB SCRIPT (MUST HELP) (NOT CLICKBAIT)

Previous Thread :: Next Thread 
Telasim0 is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
03 Apr 2017 03:35 PM
whats wrong
Report Abuse
Telasim0 is not online. Telasim0
Joined: 10 Jun 2011
Total Posts: 2263
03 Apr 2017 03:35 PM
NVM I FIGURED IT OUT
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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 is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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 is not online. Telasim0
Joined: 10 Jun 2011
Total Posts: 2263
03 Apr 2017 03:40 PM
Thank you!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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