it doesnt give error msgs but it wont save i have API services enabled no clue why it isnt working please help!
''' local dataStoreService = game:GetService("DataStoreService") local gameStore = dataStoreService:GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstat = Instance.new("Folder" , plr)`enter code here`
leaderstat.Name = "leaderstats"
local Currency = Instance.new("IntValue" , leaderstat)
Currency.Name = "Currency"
Currency.Value = 1
local CurrencyData
local success, errorMsg = pcall(function()
CurrencyData = gameStore:GetAsync(plr.UserId .. "-Currency")
end)
if success == true then
Currency.Value = CurrencyData
else
print("Cant recover data because " .. errorMsg)
end
end)
--Save data when server shut down
game:BindToClose(function()
for i , plr in pairs(game.Players:GetChildren()) do
local success , errorMsg = pcall(function()
gameStore:SetAsync(plr.UserId .. "-level" , plr.leaderstats.Currency.Value)
end)
if success then
print("Data Secured")
else
print("Error while saving data because " .. errorMsg)
end
end
end)
--Save data when somebody leaves
game.Players.PlayerRemoving:Connect(function(plr)
for i , plr in pairs(game.Players:GetChildren()) do
local success , errorMsg = pcall(function()
gameStore:SetAsync(plr.UserId .. "-level" , plr.leaderstats.Currency.Value)
end)
if success then
print("Data Secured")
else
print("Error while saving data because " .. errorMsg)
end
end
end)'''