--Services
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
--DataStore
local StageDS = DataStoreService:GetOrderedDataStore("Stage")
--Functions
function PlayerJoined(Player)
local StatsF = Instance.new("Folder", Player)
StatsF.Name = "leaderstats"
local StageV = Instance.new("IntValue", StatsF)
StageV.Name = "Stage"
StageV.Value = 0
local Rebirths = Instance.new("IntValue", StatsF)
Rebirths.Name = "Rebirths"
Rebirths.Value = 0
local StageC = Instance.new("IntValue", StatsF)
StageC.Name = "Current_Stage"
StageC.Value = 0
if StageDS:GetAsync(Player.UserId) ~= nil and StageDS:GetAsync(Player.UserId) ~= {} then
local Tries = 0
local function Try()
Tries = Tries + 1
print("Try ("..Tries..") to load ("..Player.Name..") Stats!")
local Success, Error = pcall(function()
local Get = StageDS:GetAsync(Player.UserId)
StageV.Value = Get.StageV
StageC.Value = Get.StageV
Rebirths.Value = Get.Rebirths
end)
if Success then
print("Success loading ("..Player.Name..") Stats!")
StatsF.Parent = Player
else
if Tries <= 10 then
Try()
else
print("Error loading ("..Player.Name..") Stats!")
Player:Kick("Failed to load Stats!")
end
end
end
end
end
function PlayerLeft(Player)
local StatsF = Player.leaderstats
local StageV = StatsF.Stage
local Tries = 0
local function Try()
Tries = Tries + 1
print("Try ("..Tries..") to save ("..Player.Name..") Stats!")
local Success, Error = pcall(function()
StageDS:SetAsync(Player.UserId, {StageV = Player.Stats.Stage.Value, Rebirths = Players.Stats.Rebirths.Value})
end)
if Success then
print("Success saving ("..Player.Name..") Stats!")
StatsF.Parent = Player
else
if Tries <= 10 then
Try()
else
print("Error saving ("..Player.Name..") Stats!")
end
end
end
Try()
end
Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerLeft)
game:BindToClose(function()
for i,Player in pairs(Players:GetPlayers()) do
coroutine.wrap(PlayerLeft)(Player)
end
end)
i have tried multiple things, i don’t really see anything wrong with the code, so what could be the problem? It actually worked before, but then something went wrong.
Interesting, i just noticed…I put it outside, and whenever i run the game it kicks me every time because the data failed to load, which is meant to happen but its only meant to happen as a last resort, here it kicks me EVERY TIME, which i guess means i should look inside of the PlayerJoined function.
I guess this works, but the try function goes on FOREVER and never stops, and for the player leave it only tries a few times and doesnt tell me if the players data is saved or not.
also there are few errors, “Not Running script because past shutdown deadline (server error)”, and also “DataStoreService: ValueNotAllowed: Dictionary is not allowed in data stores. API: SetAsync, Data Store: Stage”
weird, now it gives me an infinite yield warning for a LOT of my scripts: "Infinite yield possible on ‘Players.GagaGamesOfficial:WaitForChild(“leaderstats”)’:
Make your game so it don’t need to be loaded asap … idk. That’s what I do.
I use one that waits 30 seconds for player data then wait 30 more to load pets.
i got a new error for some reason: “21:56:09.272 ServerScriptService.Scripts.StagesData:111: attempt to index number with ‘StageV’ - Server - StagesData:111”
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local StageDS = DataStoreService:GetOrderedDataStore("Stage")
local function PlayerJoined(Player)
local StatsF = Instance.new("Folder", Player)
StatsF.Name = "leaderstats"
local StageV = Instance.new("IntValue", StatsF)
StageV.Name = "Stage"
StageV.Value = 0
local Rebirths = Instance.new("IntValue", StatsF)
Rebirths.Name = "Rebirths"
Rebirths.Value = 0
local Data = StageDS:GetAsync(Player.UserId)
if Data then
StageV.Value = Data.StageV
Rebirths.Value = Data.Rebirths
end
end
local function PlayerLeft(Player)
local StatsF = Player:FindFirstChild("leaderstats")
if StatsF then
local StageV = StatsF:FindFirstChild("Stage")
if StageV then
StageDS:SetAsync(Player.UserId, {StageV = StatsF.Stage.Value, Rebirths = StatsF.Rebirths.Value})
end
end
end
Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerLeft)
game:BindToClose(function()
for _, Player in ipairs(Players:GetPlayers()) do PlayerLeft(Player) end
end)```
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local StageDS = DataStoreService:GetOrderedDataStore("Stage")
local function PlayerJoined(Player)
local StatsF = Instance.new("Folder", Player)
StatsF.Name = "leaderstats"
local StageV = Instance.new("IntValue", StatsF)
StageV.Name = "Stage"
StageV.Value = 0
local Rebirths = Instance.new("IntValue", StatsF)
Rebirths.Name = "Rebirths"
Rebirths.Value = 0
local StageC = Instance.new("IntValue", StatsF)
StageC.Name = "Current_Stage"
StageC.Value = 0
task.wait(2)
local function Try()
local Tries = 0
Tries = Tries + 1
print("Try ("..Tries..") to load ("..Player.Name..") Stats!")
local Success, Error = pcall(function()
local Get = StageDS:GetAsync(Player.UserId)
StageV.Value = Get.StageV
StageC.Value = Get.StageV
Rebirths.Value = Get.Rebirths
end)
if Success then
print("Success loading ("..Player.Name..") Stats!")
StatsF.Parent = Player
else
if Tries <= 10 then
Try()
else
print("Error loading ("..Player.Name..") Stats!")
Player:Kick("Failed to load Stats!")
end
end
end
Try()
end
local function PlayerLeft(Player)
local StatsF = Player:FindFirstChild("leaderstats")
if StatsF then
local StageV = StatsF:FindFirstChild("Stage")
if StageV then
local function Try()
local Tries = 0
Tries = Tries + 1
print("Try ("..Tries..") to save ("..Player.Name..") Stats!")
local Success, Error = pcall(function()
StageDS:SetAsync(Player.UserId, {StageV = StatsF.Stage.Value, Rebirths = StatsF.Rebirths.Value})
end)
if Success then
print("Success saving ("..Player.Name..") Stats!")
StatsF.Parent = Player
else
if Tries <= 10 then
Try()
else
print("Error saving ("..Player.Name..") Stats!")
end
end
end
Try()
end
end
end
Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerLeft)
game:BindToClose(function()
for _, Player in ipairs(Players:GetPlayers()) do
PlayerLeft(Player)
end
end)
Once
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local StageDS = DataStoreService:GetOrderedDataStore("Stage")
local function PlayerJoined(Player)
local StatsF = Instance.new("Folder", Player)
StatsF.Name = "leaderstats"
local StageV = Instance.new("IntValue", StatsF)
StageV.Name = "Stage"
StageV.Value = 0
local Rebirths = Instance.new("IntValue", StatsF)
Rebirths.Name = "Rebirths"
Rebirths.Value = 0
task.wait(2)
local Data = StageDS:GetAsync(Player.UserId)
if Data then
StageV.Value = Data.StageV
Rebirths.Value = Data.Rebirths
end
end
local function PlayerLeft(Player)
local StatsF = Player:FindFirstChild("leaderstats")
if StatsF then
local StageV = StatsF:FindFirstChild("Stage")
if StageV then
StageDS:SetAsync(Player.UserId, {StageV = StatsF.Stage.Value, Rebirths = StatsF.Rebirths.Value})
end
end
end
Players.PlayerAdded:Connect(PlayerJoined)
Players.PlayerRemoving:Connect(PlayerLeft)
game:BindToClose(function()
for _, Player in ipairs(Players:GetPlayers()) do PlayerLeft(Player) end
end)
Try converting the table to a JSON string before storing it, decode it back into a table when reading the table off the DataStore. Should fix the ValueNotAllowed error.