|
| 21 Oct 2017 09:15 PM |
So I've been getting help around the forums about this, the script below is supposed to be a day/night cycle that turns lights on and off. the SpotLight is inside a part named "Lightpart" and that is inside a group. I do not understand what I am doing wrong, if someone could help me out I'd greatly appreciate it. Thanks.
minutesAfterMidnight = 0
while true do
minutesAfterMidnight = minutesAfterMidnight + 1 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
end
while true do wait() for i,v in pairs(game.Workspace:GetChildren()) do if v.Name == "Lightpart" then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then SpotLight.Enabled = false Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then SpotLight.Enabled = true Material = Enum.Material.Neon end end end end |
|
|
| Report Abuse |
|
|
| |
|
| |
|
Tunicus
|
  |
| Joined: 16 Feb 2013 |
| Total Posts: 3165 |
|
|
| 21 Oct 2017 09:52 PM |
1. The first while loop is obstructing the bottom portion. The while loop runs indefinitely, and scripts run from top to bottom, so there's no way the script will ever reach the bottom loop.
2. AFAIK this is the only script affecting the TimeOfDay, so you only need to set the materials and spotlight whenever the lighting is changed. Just put the bottom portion (excluding the while loop) inside of the first loop.
3. "SpotLight.Enabled = true" "Material = Enum.Material.Neon"
You aren't indexing anything here, this should be
v.SpotLight.Enabled = true v.Material = Enum.Material.Neon |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Oct 2017 10:31 PM |
So it works now, kinda. The day/night cycle works now, but lights do not react to the day change. If I had to guess I messed up on the "for i,v". Any suggestions?
New code:
minutesAfterMidnight = 0
while true do wait()
minutesAfterMidnight = minutesAfterMidnight + 10 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do if v.Name == "Lightpart" then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then v.SpotLight.Enabled = false v.Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then v.SpotLight.Enabled = true v.Material = Enum.Material.Neon end end end end
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
kylerzong
|
  |
| Joined: 06 Aug 2011 |
| Total Posts: 659 |
|
|
| 21 Oct 2017 11:07 PM |
minutesAfterMidnight = 0
while true do wait()
minutesAfterMidnight = minutesAfterMidnight + 10 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do if v:findFirstChild("LightPart") then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then v.LightPart.SpotLight.Enabled = false v.Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then v.SpotLight.Enabled = true v.Material = Enum.Material.Neon end end end end |
|
|
| Report Abuse |
|
|
|
| 21 Oct 2017 11:11 PM |
| What's the difference between v.Name and v.FindFirstChild? |
|
|
| Report Abuse |
|
|
s3vvy
|
  |
| Joined: 24 Feb 2011 |
| Total Posts: 983 |
|
|
| 21 Oct 2017 11:13 PM |
^ yikes
Subscribe for scripting tutorials and more videos! www.youtube.com/c/SPiNClan |
|
|
| Report Abuse |
|
|
|
| 21 Oct 2017 11:15 PM |
| Also, unfortunately, still no luck :/ |
|
|
| Report Abuse |
|
|
NemeAero
|
  |
| Joined: 25 Nov 2016 |
| Total Posts: 410 |
|
|
| 21 Oct 2017 11:23 PM |
minutesAfterMidnight = 0
while true do wait()
minutesAfterMidnight = minutesAfterMidnight + 10 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do if v:findFirstChild("LightPart") then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then v.LightPart.SpotLight.Enabled = false v.Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then v.SpotLight.Enabled = true v.Material = Enum.Material.Neon end end end end
minutesAfterMidnight = 0
while true do wait()
minutesAfterMidnight = minutesAfterMidnight + 10 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do if v:findFirstChild("LightPart") then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then v.LightPart.SpotLight.Enabled = false v.Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then v.SpotLight.Enabled = true v.Material = Enum.Material.Neon end end end end
minutesAfterMidnight = 0
while true do wait()
minutesAfterMidnight = minutesAfterMidnight + 10 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do if v:findFirstChild("LightPart") then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then v.LightPart.SpotLight.Enabled = false v.Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then v.SpotLight.Enabled = true v.Material = Enum.Material.Neon end end end end
minutesAfterMidnight = 0
while true do wait()
minutesAfterMidnight = minutesAfterMidnight + 10 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do if v:findFirstChild("LightPart") then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then v.LightPart.SpotLight.Enabled = false v.Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then v.SpotLight.Enabled = true v.Material = Enum.Material.Neon end end end end
minutesAfterMidnight = 0
while true do wait()
minutesAfterMidnight = minutesAfterMidnight + 10 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do if v:findFirstChild("LightPart") then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then v.LightPart.SpotLight.Enabled = false v.Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then v.SpotLight.Enabled = true v.Material = Enum.Material.Neon end end end end
minutesAfterMidnight = 0
while true do wait()
minutesAfterMidnight = minutesAfterMidnight + 10 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do if v:findFirstChild("LightPart") then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then v.LightPart.SpotLight.Enabled = false v.Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then v.SpotLight.Enabled = true v.Material = Enum.Material.Neon end end end end
minutesAfterMidnight = 0
while true do wait()
minutesAfterMidnight = minutesAfterMidnight + 10 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do if v:findFirstChild("LightPart") then
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then v.LightPart.SpotLight.Enabled = false v.Material = Enum.Material.Plastic end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then v.SpotLight.Enabled = true v.Material = Enum.Material.Neon end end end end
This message has been approved by @NemeAero on ROBLOX, Twitter, and Instagram! Go follow me! |
|
|
| Report Abuse |
|
|
| |
|