local DataStoreService = game:GetService("DataStoreService")
local DataStore1 = DataStoreService:GetDataStore("DataStore1")
game.Players.PlayerAdded:Connect(function(player)
local PlayerUserId = "Player_"..player.UserId
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Credits = Instance.new("IntValue", leaderstats)
Credits.Name = "Credits"
local Research = Instance.new("IntValue", leaderstats)
Research.Name = "Research"
--Load Data
local data
local success, errormessage = pcall(function()
data = DataStore1:GetAsync(PlayerUserId)
end)
if data ~= nil and success then
data[Credits.Value] = Credits.Value
data[Research.Value] = Research.Value
print("21")
elseif data == nil and success then
data[Credits.Value] = 500
data[Research.Value] = 10--setting it to the default amount if they dont have date
end
end)
print("27")
game.Players.PlayerRemoving:Connect(function(player)
local PlayerUserId = "Player_"..player.UserId
print("30")
local data = {}
for i, v in pairs(player.leaderstats:GetChildren())do
table.insert(data, v.value)
end
print("34")
local success, errormessage = pcall(function()
DataStore1:SetAsync(PlayerUserId,data)
end)
if success then
print("Data Successfully Saved")
else
print("There was an error saving data")
warn(errormessage)
end
end)
The problem might lie in lines between 27 and 34 which don't print the numbers

1 comment
God Bless you! Thank you so much, spent 2 days trying to figure this out, thank you again.