Dribben
|
  |
| Joined: 11 Feb 2012 |
| Total Posts: 25 |
|
|
| 17 Feb 2016 06:48 PM |
Hello! I am quite a noob to the scripting community, but I'm trying very hard to learn! I have attempted to create a script that makes my baseplate go from red to blue very fast. This is what I have:
local myBasePlate = game.Workspace.Baseplate
local function Red() myBasePlate.BrickColor = BrickColor.Red() print("RED")--This is to see that it is switching. end
local function Blue() myBasePlate.BrickColor = BrickColor.Blue() print("BLUE")--This is to see that it is switching. end
if Red() then Blue() else Red() end --IT DOESN'T WORK!! D: D: D: Please help!
|
|
|
| Report Abuse |
|
|
goro7
|
  |
| Joined: 01 Jul 2009 |
| Total Posts: 735 |
|
|
| 17 Feb 2016 06:50 PM |
Like this?
local myBasePlate = game.Workspace.Baseplate
local function Red() myBasePlate.BrickColor = BrickColor.Red() print("RED")--This is to see that it is switching. end
local function Blue() myBasePlate.BrickColor = BrickColor.Blue() print("BLUE")--This is to see that it is switching. end
while wait() do if myBasePlate.BrickColor == BrickColor.Red() then Blue() else Red() end |
|
|
| Report Abuse |
|
|
Dribben
|
  |
| Joined: 11 Feb 2012 |
| Total Posts: 25 |
|
|
| 17 Feb 2016 07:24 PM |
| Didn't work. You never finished the "while wait() do" string. |
|
|
| Report Abuse |
|
|
|
| 17 Feb 2016 07:26 PM |
Here's a neat method that uses nested function calls to escape looping.
local part = workspace.Baseplate
function blue() part.BrickColor=BrickColor.Blue() wait() red() end
function red() part.BrickColor=BrickColor.Red() wait() blue() end
blue()
That might work |
|
|
| Report Abuse |
|
|
Dribben
|
  |
| Joined: 11 Feb 2012 |
| Total Posts: 25 |
|
|
| 17 Feb 2016 07:34 PM |
Wow! I just did that, trying to figure it out! Here it is now:
local myBasePlate = game.Workspace.Baseplate
local function Red() myBasePlate.BrickColor = BrickColor.Red() print("RED")--This is to see that it is switching. end
local function Gray() myBasePlate.BrickColor = BrickColor.DarkGray() print("GRAY")--This is to see that it is switching. end
if myBasePlate.BrickColor == BrickColor.Red() then wait(2) Gray() end
if myBasePlate.BrickColor == BrickColor.DarkGray() then wait(2) Red() end
This works quite well, since the baseplate is initially Dark Gray. The only thing I see is that after it switches to Red, it doesn't switch back to Gray again. I don't know why, though.
|
|
|
| Report Abuse |
|
|
|
| 17 Feb 2016 07:36 PM |
local myBasePlate = game.Workspace.Baseplate
local function Red() myBasePlate.BrickColor = BrickColor.Red() print("RED")--This is to see that it is switching. end
local function Gray() myBasePlate.BrickColor = BrickColor.DarkGray() print("GRAY")--This is to see that it is switching. end
while true do if myBasePlate.BrickColor == BrickColor.Red() then wait(2) Gray() end
if myBasePlate.BrickColor == BrickColor.DarkGray() then wait(2) Red() end end |
|
|
| Report Abuse |
|
|
Dribben
|
  |
| Joined: 11 Feb 2012 |
| Total Posts: 25 |
|
|
| 17 Feb 2016 07:47 PM |
| Ah, that worked! Magnificent! Thank you! I haven't learned the "while true do" function yet. I'll keep researching the functions to make more scripts without asking for help. Thank you! |
|
|
| Report Abuse |
|
|
| |
|
Dribben
|
  |
| Joined: 11 Feb 2012 |
| Total Posts: 25 |
|
|
| 18 Feb 2016 08:45 PM |
| For some odd reason this script has started to crash my Roblox studio. Do you know why? |
|
|
| Report Abuse |
|
|