Basically when you trigger a prompt it changes the time of the day from day to night, and, if you trigger it again, from night to day. The problem is that the transition from night to day does not seem to work and I cant figure out the reason.
here is the script. Its parent is the proximity prompt
local lighting = game:GetService("Lighting")
local prompt = script.Parent.ProximityPrompt
prompt.Triggered:Connect(function(player)
if prompt.ActionText == "Night" then
-- Getting the lighting object
local lighting = game:GetService("Lighting")
-- Defining the time of day you want to transition to
local timeOfDay = 24
-- Defining the duration of the transition in seconds
local duration = 3
-- Getting the starting time of day
local start = lighting.ClockTime
-- Calculating the end time of day
local target = (timeOfDay - math.floor(timeOfDay)) * 24
-- Defining the rate of change
local rate = (target - start) / duration
-- Defining the end time
local endTime = tick() + duration
-- Loop until the end time is reached
while tick() < endTime do
-- Updating the clock time
lighting.ClockTime = lighting.ClockTime + rate * wait()
end
-- Setting the final time of day
lighting.ClockTime = target
prompt.ActionText = "Day"
script.Parent.Parent.Parent.Parent.Lighting.FogColor = Color3.fromRGB(85, 0, 255)
for _, ff in workspace.SoundRegions.LobbyArea:GetChildren() do
ff.Enabled = true
end
elseif prompt.ActionText == "Day" then
-- Getting the lighting object
local lighting = game:GetService("Lighting")
-- Defining the time of day you want to transition to
local timeOfDay2 = 10
-- Defining the duration of the transition in seconds
local duration = 3
-- Getting the starting time of day
local start = lighting.ClockTime
-- Calculating the end time of day
local target = (timeOfDay2 - math.floor(timeOfDay2)) * 24
-- Defining the rate of change
local rate = (target - start) / duration
-- Defining the end time
local endTime = tick() + duration
-- Loop until the end time is reached
while tick() < endTime do
-- Updating the clock time
lighting.ClockTime = lighting.ClockTime + rate * wait()
end
-- Setting the final time of day
lighting.ClockTime = target
prompt.ActionText = "Night"
script.Parent.Parent.Parent.Parent.Lighting.FogColor = Color3.fromRGB(144, 228, 248)
for _, ff in workspace.SoundRegions.LobbyArea:GetChildren() do
ff.Enabled = false
end
end
end)
Thank you in advance for the help