local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") local player = game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local collectibles = Instance.new("IntValue") collectibles.Name = "Collectibles" collectibles.Parent = leaderstats collectibles.Value = workspace.Collectibles.Value local level = Instance.new("IntValue") level.Name = "Level" level.Parent = leaderstats level.Value = 1 player.RespawnLocation = workspace.Level1.L1Spawn local playerUserID = "Player_"..player.UserId local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(playerUserID) end) if success then collectibles.Value = data end end) game.Players.PlayerRemoving:Connect(function() local playerUserID = "Player_"..player.UserId local data = player.leaderstats.collectibles.Value local success, errormessage = pcall(function() myDataStore:SetAsync(playerUserID, data) end) if success then print("data saved") else print("data not saved") warn(errormessage) end end)
I fixed the problem, was just some minor capitalization errors on my part.
First of all Remember to turn API Services on, so you need to publish the game and go to game settings and turn API Services on
Second of all it does not work in roblox studio
Third of all your good to go!