Code below won't load data, no errors, I have no idea what's going on.
local dataStoreService = game:GetService("DataStoreService")
local cubeDataStore = dataStoreService:GetDataStore("Cubes")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local cubesmade = Instance.new("IntValue",leaderstats)
cubesmade.Name = "Cubes"
cubesmade.Value = 0
local playerUserId = "player_"..player.UserId
local cubeData
local success, errormessage = pcall(function()
cubeData = cubeDataStore:GetAsync(playerUserId)
end)
if success then
cubesmade.Value = cubeData
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "player_"..player.UserId
local cubeValue = player.leaderstats.Cubes.Value
local success, errormessage = pcall(function()
cubeDataStore:SetAsync(playerUserId, cubeValue)
end)
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
local playerUserId = "player_"..player.UserId
local cubeValue = player.leaderstats.Cubes.Value
local success, errormessage = pcall(function()
end)
cubeDataStore:SetAsync(playerUserId, cubeValue)
end
end)

1 comment
Looks fine, after you checking if success is true add an else and then print the error message because your code wont print one unless you tell it to from the pcall.