Hello!
I was wondering, how do you save a value? (For example, the current daytime.)
I’m trying to make a fix lighting command.
Hello!
I was wondering, how do you save a value? (For example, the current daytime.)
I’m trying to make a fix lighting command.
but, what do you mean by ‘save’?
you can save this value in DataStore.
here is an example of how you can save a table with certain values, you can change it to the time value as you want
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("ServerData")
-- Loading our Table.
local function LoadTable(Key)
local Data
pcall(function()
Data = DataStore:GetAsync(Key)
end)
if Data then
return Data
end
end
-- Saving our Table.
local function SaveTable(Key, DataToSave)
pcall(function()
DataStore:SetAsync(Key, DataToSave)
end)
end
-- Usage Example
local ServerData = LoadTable("ServerData")
if ServerData then
print(ServerData.John.Age)
print(ServerData.John.Hair)
print(ServerData.Kyle.Age)
print(ServerData.Kyle.Hair)
else
local People = {
["John"] = {Age = 18, Hair = "Blue"},
["Kyle"] = {Age = 35, Hair = "White"}
}
SaveTable("ServerData", People)
end
You can use SetAsync to save a value.
Demonstration:
local DataStoreService = game:GetService("DataStoreService")
local LightingData = DataStoreService:GetDataStore("LightingData")
local value = workspace.Value.Value
LightingData:SetAsync(value.Value)
Like saving the daytime of when the server started, so that when it changes because of an unwanted instance I can revert it back to what it was before.