Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't this data script won't load or nor save?

Asked by 5 years ago
Edited 5 years ago

``local datastore = game:GetService("DataStoreService")

local data1 = datastore:GetDataStore("Data1")

game.Players.PlayerAdded:Connect(function(player)

local Data = Instance.new("Folder",player)

Data.Name = "leaderstats"

local cash = Instance.new("IntValue", Data)

cash.Name = "Cash"

cash.Value = data1:GetAsync(player.UserId) or 10

data1:GetAsync(player.UserId, cash.Value)

cash.Changed:Connect(function()

    data1:GetAsync(player.UserId, cash.Value)

end)

game.Players.PlayerRemoving:Connect(function()

data1:GetAsync(player.UserId, cash.Value)

end)

while wait(30) do

data1:GetAsync(player.UserId, cash.Value)

end

end)

Help me no data saving script works for me.

0
Ok first off for the love of everything holy do not make it save every 30 seconds. Make it load when they join and save when they leave. kittonlover101 201 — 5y
0
And possibly every time something really important happens. kittonlover101 201 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

First do not use :GetAsync() when updated or overwrite the values it make the server thinks that you use the Data Store more complicated. You need a limit. So for the limit of the :GetAsync() is 60+ number of players * 10 requests per minute. So if you have 10 players, so 60+10*10 = 700 request per minute so for this if you have more than 700 request per minute it maybe some bugs happen maybe if you have 100 coins makes 10 coins or if you have 20 coins makes 100 coins and so on. And tip, do not make server complicated in data store. So copy this script.

local datastore = game:GetService("DataStoreService")
local data1 = datastore:GetDataStore("Data1")
game.Players.PlayerAdded:Connect(function(player)
local Data = Instance.new("Folder",player)
Data.Name = "leaderstats"
local cash = Instance.new("IntValue", Data)
cash.Name = "Cash"
cash.Value = data1:GetAsync(player.UserId) or 10
end)
game.Players.PlayerRemoving:Connect(function()
data1:GetAsync(player.UserId, cash.Value)
end)

-- For auto saving if you have a auto saved data
while wait(60) do -- to make request per minute less and worked.
data1:GetAsync(player.UserId, cash.Value)
end

If not worked open the output. To open the output, click View on top the window, then click Output.

Ad

Answer this question