Hi, I made a script so if the player triggers a prompt the lighting change form day to night and from night to day. Basically I want that if a player leaves the experience and then rejoins, prompt settings get saved and they are the same of the players last visist.
To make it clear:
If the plr enables night via prompt and leaves the game, when he joins again its still night and the prompt shows the right actiontext.
Im new to coding and i tried with datastores but it didnt work. Do u know a way to do this?
the script:
local lighting = game:GetService("Lighting")
local prompt = workspace.Misc.Nyx.ProximityPrompt
local plr = game.Players.LocalPlayer
prompt.Triggered:Connect(function(plr)
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 = 20
-- 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"
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 timeOfDay = 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 = 10
-- 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"
lighting.FogColor = Color3.fromRGB(144, 228, 248)
for _, ff in workspace.SoundRegions.LobbyArea:GetChildren() do
ff.Enabled = false
end
end
end)