|
| 27 Oct 2015 02:56 PM |
I made a police siren. Get on my level ;)
Part1 = game.workspace.Part1 Part2 = game.workspace.Part2
while 1 == 1 do wait(.3) Part1.BrickColor = BrickColor.new("Dark blue") Part2.BrickColor = BrickColor.new("Really red") wait(.3) Part1.BrickColor = BrickColor.new("Really red") Part2.BrickColor = BrickColor.new("Dark blue")
end
I'm actually quite proud I whipped this up in 1 minute. |
|
|
| Report Abuse |
|
|
AkaLua
|
  |
| Joined: 27 Jul 2012 |
| Total Posts: 526 |
|
|
| 27 Oct 2015 02:58 PM |
Are you just starting out learning LUA?
-____________________________- |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
| |
|
|
| 27 Oct 2015 03:01 PM |
local Part1 = workspace.Part1 local Part2 = workspace.Part2
while wait(.3) do Part2.BrickColor = BrickColor.new("Really red") wait(.3) Part2.BrickColor = BrickColor.new("Dark blue") end
betta? betta |
|
|
| Report Abuse |
|
|
|
| 27 Oct 2015 03:04 PM |
Well I kinda cheated because I program in javascript. I understand the concepts of everything in Lua, just playing around in studio learning the syntax. Here is the new script. I made it a model:
Part1 = game.workspace.Sirens.Part1 Part2 = game.workspace.Sirens.Part2
while 1 == 1 do wait(.3) Part1.BrickColor = BrickColor.new("Dark blue") Part2.BrickColor = BrickColor.new("Really red") wait(.3) Part1.BrickColor = BrickColor.new("Really red") Part2.BrickColor = BrickColor.new("Dark blue")
end
|
|
|
| Report Abuse |
|
|
|
| 27 Oct 2015 03:04 PM |
| Pretty neat! Keep practicing to remember and excel :D |
|
|
| Report Abuse |
|
|
|
| 27 Oct 2015 03:06 PM |
I remember my first script...
It removed the Shirt and Pants from the Players model when they joined. |
|
|
| Report Abuse |
|
|
|
| 27 Oct 2015 03:09 PM |
Just a tip, you can use 'true' instead of '1 == 1'
while true do --code end
Try to not get stuck in an infininte loop tho. One way you can avoid this is by using this;
while wait(SECONDS) do --code end
Thatll run the code every (SECONDS)
Instance.new("BodyVelocity",SenseiWarrior).velocity = CFrame.new(SenseiWarrior.Torso.Position,YourGirlsDMs.Position).lookVector * 10 |
|
|
| Report Abuse |
|
|
|
| 27 Oct 2015 03:13 PM |
You want to know an even more fun way to avoid an infinite loop? Make a count variable: I just came up with this and it seems to work fine!
Part1 = game.workspace.Sirens.Part1 Part2 = game.workspace.Sirens.Part2 count = 10 x = 0
while x < count do wait(.3) Part1.BrickColor = BrickColor.new("Dark blue") Part2.BrickColor = BrickColor.new("Really red") wait(.3) Part1.BrickColor = BrickColor.new("Really red") Part2.BrickColor = BrickColor.new("Dark blue") x = x + 1 end
|
|
|
| Report Abuse |
|
|
|
| 27 Oct 2015 03:14 PM |
| Numerical for or repeat loops are better for that use |
|
|
| Report Abuse |
|
|
|
| 27 Oct 2015 03:18 PM |
| I see. Just saying it is possible. I need to learn all the logical functions in Lua. I will be doing my research. Add me, stay in touch. I plan on making a game soon. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 27 Oct 2015 03:24 PM |
You can use the global "script" variable to get a reference to the script object, so if you have the script inside the model you can get the parts from the Parent.
local A = script.Parent.Part1 local B = script.Parent.Part2 local Running = false
A.Changed:connect(function() if not Running then Running = true wait(0.3) local c = B.BrickColor B.BrickColor = A.BrickColor Running = false A.BrickColor = c end end)
local c = B.BrickColor B.BrickColor = A.BrickColor A.BrickColor = c
|
|
|
| Report Abuse |
|
|
|
| 27 Oct 2015 03:34 PM |
| What is the point of the Running variable? I understand everything the script is doing and why, but why do you need that third variable? |
|
|
| Report Abuse |
|
|
|
| 27 Oct 2015 03:41 PM |
| because then it will run from u1 |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 27 Oct 2015 03:43 PM |
| Because the Changged event is bound to fire while the script is waiting to change(Events run the connected functions on new threads) from something else so using that check you can only allow color change after the waiting is done. |
|
|
| Report Abuse |
|
|
| |
|