My data save script dont work but on other place it works perfectly (api services is enabled and http requests too)
Script:
local Players = game:GetService(“Players”)
local DSS = game:GetService(“DataStoreService”)
local Data1 = DSS:GetDataStore(“Data”)
local RS = game:GetService(“RunService”)
local RS2 = game:GetService(“ReplicatedStorage”)
local Event = RS2:WaitForChild(“Remotes”).AddValue
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Strengh = Instance.new("IntValue", leaderstats)
Strengh.Name = "Strengh"
local Wins = Instance.new("IntValue", leaderstats)
Wins.Name = "Wins"
local Rebirths = Instance.new("IntValue", leaderstats)
Rebirths.Name = "Rebirths"
local PlayerData
local Success, ErrorMsg = pcall(function()
local PlayerKey = player.UserId
PlayerData = Data1:GetAsync(PlayerKey)
end)
if Success then
if PlayerData then
Strengh.Value = PlayerData[1]
Wins.Value = PlayerData[2]
Rebirths.Value = PlayerData[3]
end
else
warn(ErrorMsg)
end
Event.OnServerEvent:Connect(function(player)
Strengh.Value += 1
end)
end)
local function SaveData(player)
local user = player
local leaderstats = user:WaitForChild(“leaderstats”)
local PlayerData = {
leaderstats.Strengh.Value,
leaderstats.Wins.Value,
leaderstats.Rebirths.Value
}
print(PlayerData)
local PlayerKey = "player_"..player.UserId
local Success, ErrorMsg = pcall(function()
Data1:SetAsync(PlayerKey, PlayerData)
end)
if not Success then
warn(ErrorMsg)
end
end
Players.PlayerRemoving:Connect(function(player)
SaveData(player)
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
task.spawn(function()
SaveData(player)
end)
end
task.wait(5)
end)