game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local seconds = Instance.new("NumberValue", leaderstats)
seconds.Name = "Seconds"
seconds.Value = 0
local success, data = pcall(function()
return SecondsStore:GetAsync(player.UserId)
end)
if success and data then
seconds.Value = data
end
if not success then
warn("Failed to load data for player: " .. player.Name)
seconds:Destroy()
player:Kick("Failed to load your data. Try again later.")
end
while wait(1) do
if seconds then
seconds.Value = seconds.Value + 1
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errorMessage = pcall(function()
SecondsStore:SetAsync(player.UserId, player.leaderstats.Seconds.Value)
end)
if not success then
warn("Failed to save data for player: " .. player.Name .. ". Error: " .. errorMessage)
end
local Success,errormessage = pcall(function()
badgeService:AwardBadge(player.UserId,276473952825522)
end)
if not Success then
warn("Failed to award badge for player: " .. player.Name .. ". Error: " .. errormessage)
end
end)
local DatastoreService = game:GetService("DataStoreService")
local SecondsStore = DatastoreService:GetOrderedDataStore("PlayerSeconds")
local badgeService = game:GetService("BadgeService")
PlayerAdded is not guaranteed to be called, especially in Studio. You need to also loop through Players:GetChildren() and fire your PlayerAdded code for the players it fines. I would put this right after you hook up your PlayerAdded and PlayerRemove connections
the weird point is my public game and my studio version are both affected. player added is working since the seconds variable is created but doesnt load datastore without any sort of errors.