|
| 30 May 2013 06:04 AM |
Hi guys, I am trying to make it so a pointlight will be disabled at a certain time but when I test it, it says that I am attempting to compare string with boolean. How can I fix this? My guess is that I need to only have one not on the line shown below. Script: while true do wait(.1) if game.Lighting.TimeOfDay >= "06:00:00" and game.Lighting.TimeOfDay < "18:00:00" then p = game.Workspace:GetChildren() for i=1, #p do if p[i].Name == "Model" and p[i]:FindFirstChild("Lightbulb") then if p[i].Lightbulb:FindFirstChild("PointLight") ~= nil then p[i].Lightbulb.PointLight.Enabled = false end end end elseif not game.Lighting.TimeOfDay >= "06:00:00" and not game.Lighting.TimeOfDay < "18:00:00" then --This line here is where the errors at p = game.Workspace:GetChildren() for i=1, #p do if p[i].Name == "Streetlamp" then if p[i]:FindFirstChild("SpotLight") ~= nil then p[i].SpotLight.Enabled = true end end end end end |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 06:09 AM |
| I got rid of one "not" on the line where the error shows but it still says it's comparing string with boolean. How could I solve this? Thanks. |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 06:11 AM |
Try putting
elseif game.Lighting.TimeOfDay <= 06:00:00 and game.Lighting.TimeOfDay > 18:00:00
Soups on, everybody! ~LuaLearners Writer~ |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 06:12 AM |
You were using math on strings, which is the same as putting
if TimeOfDay > "Pie" then
Removing the speech marks should work.
Soup's on, everybody! ~LuaLearners Writer~ |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 06:18 AM |
| I got an error without putting in speech marks on the times but I didn't get an error with the speech marks but the lights don't come back on. They turn off fine but will never come back on. I didn't see anything in the output. |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 06:20 AM |
Post your edited script please.
Soup's on, everybody! ~LuaLearners Writer~ |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 06:23 AM |
I forgot to change the bottom things (the pointlight, find model, etc) to match the top ones but it still doesn't work for me, I don't get any errors in output but the lights will turn off but won't come back on. :| Script: while true do wait(.1) if game.Lighting.TimeOfDay >= "06:00:00" and game.Lighting.TimeOfDay < "18:00:00" then p = game.Workspace:GetChildren() for i=1, #p do if p[i].Name == "Model" and p[i]:FindFirstChild("Lightbulb") then if p[i].Lightbulb:FindFirstChild("PointLight") ~= nil then p[i].Lightbulb.PointLight.Enabled = false end end end elseif game.Lighting.TimeOfDay < "06:00:00" and game.Lighting.TimeOfDay >= "18:00:00" then p = game.Workspace:GetChildren() for i=1, #p do if p[i].Name == "Model" and p[i]:FindFirstChild("Lightbulb") then if p[i].Lightbulb:FindFirstChild("PointLight") ~= nil then p[i].Lightbulb.PointLight.Enabled = true end end end end end |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 07:01 AM |
| I've got a cookie on the line for someone... :P |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 10:59 AM |
Bump initiation sequence... ERROR: You bumped. Have a great day. Anyway, can someone help me, I'm unsure on how to fix it. |
|
|
| Report Abuse |
|
|
zakary99
|
  |
| Joined: 19 Jan 2010 |
| Total Posts: 1095 |
|
|
| 30 May 2013 12:07 PM |
Your for statement is incorrect.
for _,v in pairs (game.Workspace:GetChildren()) do if v.Name == "Model" and v:FindFirstChild("LightBulb") then if v.LightBulb:FindFirstChild("PointLight") then v.LightBulb.PointLight.Enabled = false end end end
~You have to think like a Dinosaur to become a Dinosaur~ |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 03:36 PM |
Fiddled around with the script a bit and same thing happens. The lights turn off when it's 06:00:00 but when it reaches 18:00:00, they don't turn back on. I'm now seriously unsure why this won't work. Script: while true do wait(.1) if game.Lighting.TimeOfDay >= "06:00:00" and game.Lighting.TimeOfDay < "18:00:00" then for _,v in pairs (game.Workspace:GetChildren()) do if v.Name == "Model" and v:FindFirstChild("Lightbulb") then if v.Lightbulb:FindFirstChild("PointLight") then v.Lightbulb.PointLight.Enabled = false
elseif game.Lighting.TimeOfDay < "06:00:00" and game.Lighting.TimeOfDay >= "18:00:00" then for _,v in pairs (game.Workspace:GetChildren()) do if v.Name == "Model" and v:FindFirstChild("Lightbulb") then if v.Lightbulb:FindFirstChild("PointLight") then v.Lightbulb.PointLight.Enabled = true end end end end end end end end |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 03:44 PM |
use GetMinutesAfterMidnight
game.Lighting.TimeOfDay = "14:00:00" print(game.Lighting:GetMinutesAfterMidnight()) |
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 30 May 2013 03:51 PM |
You have to use the :GetMinutesAfterMidnight() method in this case. I'd say not to use a while loop with a wait(.1) in it, it'll get very laggy. Instead, use the LightingChanged event of Lighting.
local light = Game.Lighting -- created a local variable called 'light' that refers to game.Lighting
function setLights(state) -- a function for switching the lights on and off if state:lower() == 'off' then for _, v in pairs(Workspace:GetChildren()) do if v:IsA("Model") and v:FindFirstChild("Lightbulb") and v:FindFirstChild("Lightbulb"):FindFirstChild("PointLight") then v.Lightbulb.PointLight.Enabled = false; end end elseif state:lower() == 'on' then for _, v in pairs(Workspace:GetChildren()) do if v:IsA("Model") and v:FindFirstChild("Lightbulb") and v:FindFirstChild("Lightbulb"):FindFirstChild("PointLight") then v.Lightbulb.PointLight.Enabled = true; end end end
function whenTimeChanges() -- a function that tells the script what to do when the time changes local hour = light:GetMinutesAfterMidnight() / 60 -- gets the current hour in military time if hour > 6 and hour < 18 then -- if the hour is in between 6 and 18 then setLights("off") else setLights("on") end end
light.LightingChanged:connect(whenTimeChanges) -- connecting event 'LightingChanged' to function 'whenTimeChanges'
while true do wait(.1) local hour = game.Lighting:GetMinutesAfterMidnight() / 60; if hour > 6 and hour < 18 then for _,v in pairs (game.Workspace:GetChildren()) do if v:IsA("Model") and v:FindFirstChild("Lightbulb") then if v.Lightbulb:FindFirstChild("PointLight") then v.Lightbulb.PointLight.Enabled = false else for _,v in pairs (game.Workspace:GetChildren()) do if v.Name == "Model" and v:FindFirstChild("Lightbulb") then if v.Lightbulb:FindFirstChild("PointLight") then v.Lightbulb.PointLight.Enabled = true end end end end end end end end |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 04:10 PM |
| I tested it but the lights didn't turn off or on at the times specified. I'm getting really confused right now... |
|
|
| Report Abuse |
|
|
|
| 30 May 2013 04:21 PM |
| I tested it again but it said attempt to call a nil value but it didn't say what line or script... :O |
|
|
| Report Abuse |
|
|
|
| 31 May 2013 07:05 AM |
Has anyone got a solution to my problem? It seems weird why it isn't working. Also, there wasn't anything on the output. Script:
local light = game.Lighting -- created a local variable called 'light' that refers to game.Lighting
function setLights(state) -- a function for switching the lights on and off if state:lower() == 'off' then for _, v in pairs(Workspace:GetChildren()) do if v:IsA("Model") and v:FindFirstChild("Lightbulb") and v:FindFirstChild("Lightbulb"):FindFirstChild("PointLight") then v.Lightbulb.PointLight.Enabled = false; end end elseif state:lower() == 'on' then for _, v in pairs(Workspace:GetChildren()) do if v:IsA("Model") and v:FindFirstChild("Lightbulb") and v:FindFirstChild("Lightbulb"):FindFirstChild("PointLight") then v.Lightbulb.PointLight.Enabled = true; end end end
function whenTimeChanges() -- a function that tells the script what to do when the time changes local hour = light:GetMinutesAfterMidnight() / 60 -- gets the current hour in military time if hour > 6 and hour < 18 then -- if the hour is in between 6 and 18 then setLights("off") else setLights("on") end end end
light.LightingChanged:connect(whenTimeChanges) -- connecting event 'LightingChanged' to function 'whenTimeChanges' |
|
|
| Report Abuse |
|
|