-
What do you want to achieve? Use Data Store
-
What is the issue? this thing just started happening recently and I don’t know what caused it or how did it happen
-
What solutions have you tried so far? tried looking on DevForum, but still no solution, I also created a new game and the data store not working as well, so the cause of the problem is either my script or the roblox studio itself
note: My data stores work before this thing happened, it just started happening recently. and yeah i tried to test if it works in roblox player, but same result. (No errors as well)
Data Store Script
local dataStore = game:GetService("DataStoreService")
local playerStatsData = dataStore:GetDataStore("TestStat1")
game.Players.PlayerAdded:Connect(function(player)
local userId = player.UserId
local dataFolder = Instance.new("Folder")
dataFolder.Name = "PlayerData"
dataFolder.Parent = player
local playerStats = Instance.new("Folder")
playerStats.Name = "PlayerStats"
playerStats.Parent = dataFolder
-- Stats ==
local maxHealth = Instance.new("IntValue")
maxHealth.Name = "MaxHealth"
maxHealth.Parent = playerStats
local health = Instance.new("IntValue")
health.Name = "Health"
health.Parent = playerStats
local maxStamina = Instance.new("IntValue")
maxStamina.Name = "MaxStamina"
maxStamina.Parent = playerStats
local stamina = Instance.new("IntValue")
stamina.Name = "Stamina"
stamina.Parent = playerStats
local maxOxygen = Instance.new("IntValue")
maxOxygen.Name = "MaxOxygen"
maxOxygen.Parent = playerStats
local oxygen = Instance.new("IntValue")
oxygen.Name = "Oxygen"
oxygen.Parent = playerStats
local speed = Instance.new("IntValue")
speed.Name = "Speed"
speed.Parent = playerStats
-- Load Data ---------------------------------------------->
local data
local success, err = pcall(function()
data = playerStatsData:GetAsync(userId .. "_Stats")
end)
if data then
for i, item in pairs(playerStats:GetChildren()) do
item.Value = data[item.Name]
end
else
maxHealth.Value = 100
health.Value = 100
maxOxygen.Value = 100
oxygen.Value = 100
maxStamina.Value = 60
stamina.Value = 60
end
end)
local function createDataTable(player)
local dataFolder = player:WaitForChild("PlayerData")
local playerStats = dataFolder:WaitForChild("PlayerStats")
local statsTable = {}
for i, item in pairs(playerStats:GetChildren()) do
statsTable[item.Name] = item.Value
end
end
game.Players.PlayerRemoving:Connect(function(player)
local statsTable = createDataTable(player)
local userId = player.UserId
local success, err = pcall(function()
playerStatsData:UpdateAsync(userId .. "_Stats", function(recentData)
local dataTable = recentData or {}
for item, value in pairs(dataTable) do
dataTable[item] = value
end
end)
end)
if err then
print(player.Name .. "'s Stats failed to save, cause: ".. err)
end
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("Experience shutting down")
end
end
wait(5)
end)
i dont really know whats going on.