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 » Scripting Helpers
Home Search
 

Re: What's wrong with this?

Previous Thread :: Next Thread 
WoodBlocks18 is not online. WoodBlocks18
Joined: 29 May 2010
Total Posts: 382
10 Nov 2013 12:41 PM
This script is supposed to make it night in 5 seconds, turn on all the lights, then 5 seconds later, it's day and the lights turn off. But, instead: It waits 5 seconds, both 'StreetLamp''s turn on, and only one 'BuildingLight' turns on. It waits 5 seconds, it becomes day, but then the BuildingLight that didn't turn on, turns on, 5 seconds later, that BuildingLight turns off, then 5 seconds later, it turns night and loops. Here's the script:

while true do
wait(5)
game.Lighting.TimeOfDay = "00:00:00"
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "StreetLamp" then
v.Part1.PointLight.Enabled = true
elseif v.Name == "BuildingLight" then
v.PointLight.Enabled = true

wait(5)
game.Lighting.TimeOfDay = "14:00:00"
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "StreetLamp" then
v.Part1.PointLight.Enabled = false
elseif v.Name == "BuildingLight" then
v.PointLight.Enabled = false
end
end
end
end
wait()
end
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
10 Nov 2013 12:44 PM
Sounds like someone doesn't indent their code. If you had, you probably would notice that you're second 'wait(5)' is underneath the 'elseif v.Name == "BuildingLight" then' bit. Therefore, as soon as your code finds 1 part named BuildingLight, it's going to change to day and turn off all the things.
Here's the fixed script. (I didn't change any words, just shifted lines around)
while true do
wait(5)
game.Lighting.TimeOfDay = "00:00:00"
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "StreetLamp" then
v.Part1.PointLight.Enabled = true
elseif v.Name == "BuildingLight" then
v.PointLight.Enabled = true
end
end
wait(5)
game.Lighting.TimeOfDay = "14:00:00"
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "StreetLamp" then
v.Part1.PointLight.Enabled = false
elseif v.Name == "BuildingLight" then
v.PointLight.Enabled = false
end
end
wait()
end

Report Abuse
WoodBlocks18 is not online. WoodBlocks18
Joined: 29 May 2010
Total Posts: 382
10 Nov 2013 12:48 PM
Sorry, I'm a total beginner. Your script works, thanks so much!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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