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 » Scripters
Home Search
 

Re: My first program in Lua :)

Previous Thread :: Next Thread 
iScriptStuffz is not online. iScriptStuffz
Joined: 11 Sep 2015
Total Posts: 348
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 is not online. AkaLua
Joined: 27 Jul 2012
Total Posts: 526
27 Oct 2015 02:58 PM
Are you just starting out learning LUA?


-____________________________-
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
27 Oct 2015 03:01 PM
k
Report Abuse
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
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
iScriptStuffz is not online. iScriptStuffz
Joined: 11 Sep 2015
Total Posts: 348
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
27 Oct 2015 03:04 PM
Pretty neat! Keep practicing to remember and excel :D
Report Abuse
colinrules10 is not online. colinrules10
Joined: 04 May 2013
Total Posts: 878
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
SenseiWarrior is not online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
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
iScriptStuffz is not online. iScriptStuffz
Joined: 11 Sep 2015
Total Posts: 348
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
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
27 Oct 2015 03:14 PM
Numerical for or repeat loops are better for that use
Report Abuse
iScriptStuffz is not online. iScriptStuffz
Joined: 11 Sep 2015
Total Posts: 348
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 is not online. 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
iScriptStuffz is not online. iScriptStuffz
Joined: 11 Sep 2015
Total Posts: 348
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
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
27 Oct 2015 03:41 PM
because then it will run from u1
Report Abuse
chimmihc is not online. 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
iScriptStuffz is not online. iScriptStuffz
Joined: 11 Sep 2015
Total Posts: 348
27 Oct 2015 03:45 PM
I see I see
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