Here is my server data store. maybe u can peek on that. As i see u did nothing wrong.
local TimeToWait = 60*10
local Time = 30
local DataStoreName = game.ReplicatedStorage.Values.ServerName.Value
local ServerDataStore = game:GetService("DataStoreService")
local ServerData = ServerDataStore:GetDataStore(DataStoreName)
local GetDataStore
local Server = {}
Server.ServerId = game.ReplicatedStorage.Values.ServerId.Value
Server.Name = DataStoreName
Server.Store = game.Workspace.Store.SurfaceGui.State
Server.StoreState = game.Workspace.Store.StoreState
Server.Bank = game.Workspace.Bank.Counter.CounterDoor.SurfaceGui.State
Server.BankState = game.Workspace.Bank.Counter.CounterDoor.Bank.BankState
Server.Restart = game.ReplicatedStorage.Values.Restart
Server.Restart1 = game.ReplicatedStorage.Values.Restart1
Server.Helper = game.ReplicatedStorage.Values.Helper
Server.spelercount = game.ReplicatedStorage.Values.SpelersCount
local ServerStoreData = {Server.ServerId.."-"..Server.StoreState.Name}
local ServerBankData = {Server.ServerId.."-"..Server.BankState.Name}
local ServerRestartData = (Server.ServerId.."-"..Server.Restart.Name)
local ServerRestart1Data = (Server.ServerId.."-"..Server.Restart1.Name)
local HelperData = (Server.ServerId.."-"..Server.Helper.Name)
local spelercountdata = (Server.ServerId.."-"..Server.spelercount.Name)
local Default = false
local function CheckState(ServerId,What)
GetDataStore = ServerData:GetAsync(ServerId)
if GetDataStore then
local Text = "Server: "..DataStoreName.. " loading..."
print(Text)
print(What.Name.." loading...")
What.Value = GetDataStore
print(What.Name.." loaded")
local Text = "Server: "..DataStoreName.. " loaded"
print(Text)
if What.Name == Server.BankState.Name and What.Value == true then
Server.Bank.Text = "Open"
Server.Bank.BackgroundColor3 = Color3.new(0, 255, 0)
print("Bank Open")
end
if What.Name == Server.StoreState.Name and What.Value == true then
Server.Store.Text = "Open"
Server.Store.BackgroundColor3 = Color3.new(0, 255, 0)
print("Store Open")
end
if What.Name == Server.Restart1.Name and What.Value == true then
Server.Restart.Value = false
Server.Restart1.Value = false
ServerData:SetAsync(ServerRestartData,Server.Restart.Value)
ServerData:SetAsync(ServerRestart1Data,Server.Restart1.Value)
end
if What.Name == Server.Restart.Name and What.Value == true then
Server.Restart1.Value = true
ServerData:SetAsync(ServerRestart1Data,Server.Restart1.Value)
local tijd = 30
local text = "Server Restarts in "..tijd
for i, player in pairs(game.Players:GetPlayers()) do
local restart = Instance.new("ScreenGui",player.PlayerGui)
restart.Name = "Restart"
restart.Parent = player.PlayerGui
local Text = Instance.new("TextLabel",restart)
Text.Name = "Text"
Text.Parent = restart
Text.Position = UDim2.new(0.20, 0, 0.15, 0)
Text.Size = UDim2.new(0, 500, 0, 500)
Text.BackgroundColor3 = BrickColor.Red().Color
Text.BackgroundTransparency = UDim2.new(0)
Text.BorderSizePixel = UDim2.new(2)
Text.Font = "Arial"
Text.Text = text
Text.TextScaled = true
local Script = game.ReplicatedStorage.Scripts.pr
local place = restart
local copy = Script:Clone()
copy.Parent = place
end
end
if What.Name == Server.BankState.Name and What.Value == false then
Server.Bank.Text = "Closed!"
Server.Bank.BackgroundColor3 = Color3.new(255, 0, 0)
print("Bank Closed")
end
if What.Name == Server.StoreState.Name and What.Value == false then
Server.Store.Text = "Closed!"
Server.Store.BackgroundColor3 = Color3.new(255, 0, 0)
print("Store Closed")
end
else
if What.Value ~= nil then
Default = What.Value
end
ServerData:SetAsync(ServerId,Default)
print("server Default")
local Text = "Server: "..DataStoreName.. " Setting..."
print(Text)
print(What.Name)
print(What.Value)
print(GetDataStore)
local Text = "Server: "..DataStoreName.. " Done"
print(Text)
if What.Name == Server.BankState.Name and What.Value == false then
Server.Bank.Text = "Closed!"
Server.Bank.BackgroundColor3 = Color3.new(255, 0, 0)
print("Store Closed")
end
if What.Name == Server.StoreState.Name and What.Value == false then
Server.Store.Text = "Closed!"
Server.Store.BackgroundColor3 = Color3.new(255, 0, 0)
print("Store Closed")
end
end
end
while true do
CheckState(spelercountdata, Server.spelercount)
wait(Time)
CheckState(ServerBankData,Server.BankState)
wait(Time)
CheckState(ServerStoreData,Server.StoreState)
wait(Time)
CheckState(HelperData, Server.Helper)
wait(Time)
CheckState(ServerRestart1Data,Server.Restart1)
wait(Time)
CheckState(ServerRestartData,Server.Restart)
wait(TimeToWait)
end
Happy scripting!
oh yeah for got this one out my otther script
ServerData:SetAsync(ServerId,What.Value)
1 comment
last one i use and onupdate function like on the first tcript funtion chackstate