What you're doing incorrectly is creating the Color3 values.
local A = "event1"
local Lighting = game.Lighting
game.Players.PlayerAdded:wait()
while true do
wait (2)
Lighting:FindFirstChild(A):Clone().Parent = game.Workspace
Lighting.TimeOfDay = "00:00:00"
Lighting.Ambient = Color3.new(0, 0, 0)
Lighting.Brightness = 0.001
Lighting.ColorShift_Bottom = Color3.new(0, 0, 0)
Lighting.ColorShift_Top = Color3.new(0, 0, 0)
Lighting.OutdoorAmbient = Color3.new(0, 0, 0)
Lighting.ShadowColor = Color3.new(0, 0, 0)
Lighting.FogColor = Color3.new(0, 0, 0)
Lighting.FogEnd = 75
Lighting.FogStart = 0
wait (1)
Lighting.TimeOfDay = "12:00:00"
Lighting.Ambient = Color3.new(0, 0, 0)
Lighting.Brightness = 1
Lighting.ColorShift_Bottom = Color3.new(0, 0, 0)
Lighting.ColorShift_Top = Color3.new(0, 0, 0)
Lighting.OutdoorAmbient = Color3.new(127/255, 127/255, 127/255)
Lighting.ShadowColor = Color3.new(178/255, 178/255, 183/255)
Lighting.FogColor = Color3.new(191/255, 191/255, 191/255)
Lighting.FogEnd = 100000
Lighting.FogStart = 0
game.Workspace:FindFirstChild(A):Destroy()
end
Here's a rundown of what changed:
Firstly, I changed all of those variable names that referenced game.Lighting to one variable: Lighting. All of those variables weren't necessary, and lessened the readability of the script.
Next, I changed the first line of the while loop, which was:
game.Lighting:findFirstChild(A):clone().Parent = game.Workspace
to this:
Lighting:FindFirstChild(A):Clone().Parent = game.Workspace
Firstly, I changed the variable that's being referenced to "Lighting", instead of game.Lighting, since we already have a variable for Lighting.
It also now uses "FindFirstChild", not "findFirstChild" (notice the case difference) since "findFirstChild" is deprecated, as well as "Clone" instead of "clone", since "clone" is also deprecated.
The main thing that I changed is the Color3.new lines in the second part of the code. You were creating Color3 values with raw numbers. The Color3 library actually takes colors as a decimal out of 1. So, you have to divide the values you want by 255 in order to get the desired result.
I changed this line
game.Workspace:findFirstChild(A):remove()
to this, which doesn't have deprecated functions:
game.Workspace:FindFirstChild(A):Destroy()
Lastly, if you want to get really advanced with how you're doing this, I'd suggest the following solution as a more easily configurable alternative:
local A = "event1"
local Lighting = game.Lighting
game.Players.PlayerAdded:wait()
local initialLighting = {
TimeOfDay = "12:00:00",
Ambient = Color3.new(0, 0, 0),
Brightness = 1,
ColorShift_Bottom = Color3.new(0, 0, 0),
ColorShift_Top = Color3.new(0, 0, 0),
OutdoorAmbient = Color3.new(127/255, 127/255, 127/255),
ShadowColor = Color3.new(178/255, 178/255, 183/255),
FogColor = Color3.new(191/255, 191/255, 191/255),
FogEnd = 100000,
FogStart = 0
}
local darkerLighting = {
TimeOfDay = "00:00:00",
Ambient = Color3.new(0, 0, 0),
Brightness = 0.001,
ColorShift_Bottom = Color3.new(0, 0, 0),
ColorShift_Top = Color3.new(0, 0, 0),
OutdoorAmbient = Color3.new(0, 0, 0),
ShadowColor = Color3.new(0, 0, 0),
FogColor = Color3.new(0, 0, 0),
FogEnd = 75,
FogStart = 0
}
while true do
wait (2)
Lighting:FindFirstChild(A):Clone().Parent = game.Workspace
for property, value in pairs(darkerLighting) do
Lighting[property] = value
end
wait (1)
for property, value in pairs(initialLighting) do
Lighting[property] = value
end
game.Workspace:FindFirstChild(A):Destroy()
end
Essentially, what this does is create two tables of various states of Lighting, using a key-value format that represents a property and its value. When the time comes to set the Lighting properties to various values, a for loop iterates through all of the properties and their values, assigning the property to its corresponding value in Lighting.
Hope this helps. Good luck!
3 comments
You might as well just do
Lighting[A]:Clone()Thank you so much!
@BlueTaslem Yeah, I suppose. But perhaps not. I have no idea of what sort of environment he's dealing with. :P