(For confusion avoidance, know that in this answer i refer to branflakes1099 in second person and to CarterTheHippo in third person.)
CarterTheHippo brought you a correct answer, i would like to give you the same but much more effecient.
So, my fellow contributor used an event. Events fire when crucial actions happen. Here are the events every instance has:
AncestryChanged (When path to instance changes) ,Changed (When any property of instance changes) ,ChildAdded (When instance gets a child) ,ChildRemoved (When instance loses a child) ,DescendantAdded (When instance itself or any instance below the parent instance gets a child) DescendantRemoving (When instance itself or any instance below the parent instance loses a child)
To know when those crucial actions happen you set up a listener for the event, like here:
game.Lighting.Changed:connect(function(property)
For we want to do, we are using the Changed event here.
This event will fire when any property of the Lighting service (in this case) changes. Notice "property" in the function - most (but probably all) events return values for functions to use. In this case we have a string of the property's name, which i chose to refer to as "property" in the function.
However, hold it! What about what Carter did?
game.Workspace.TimeOfDay.Changed(function(val)
This event looks the same but is different. Roblox provides instances which can be used to hold specific values, in which case it's StringValue here. When you use the Changed event on any value container, the event will always fire when the value changes, and never otherwise. Thus for this we never need to check if it's the value that's changed.
As i said before, his solution is correct but a bit ineffecient. What we can do with the Changed event will allow us to not require a StringValue to keep the property and an additional script to update it.
So, on our script here, for checking a specific property (in your case TimeOfDay), we can just use an if statement to see if the name of the property is TimeOfDay.
This is the final product:
game.Lighting.Changed:connect(function(property)
if property == "TimeOfDay" then
if val == "00:00:00" then
game.Lighting.Demon:Clone().Parent = game.Workspace
elseif val == "03:33:33" then
game.Workspace.Demon:Destroy()
end
end
end)
Hopefully this answer helps you understand Lua further.
1 comment
Is there any error that show up in the output?