I'm trying to write a script where every second it saves data =, but it really isn't working :/ Could anyone help?
My script:
local dataStoreService = game:GetService("DataStoreService") local myDataStore = dataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
--- Leaderstats Variables
--- Hidden Variables
local hiddenVariables = Instance.new("Folder",player)
hiddenVariables.Name = "hiddenVariables"
local eventsCompleted = Instance.new("IntValue",hiddenVariables)
eventsCompleted.Name = "eventsCompleted"
while wait(0.1)do
local playerUserId = "Player_"..player.UserId
local data
local success, errorMessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
eventsCompleted.Value = data
end
end
end)

1 comment
Trying to save every tenth of a second will result in data loss.