So I am basically making an Obby. I want' to have a leader board in which there is going to be a coins table and a checkpoint table. And the coins table is going to be saved (I applied data store). But after the script I wrote, the leader board worked but when I opened Studio again, I did not have any leader board. Please Explain.
Here's the script:
local dataStoreService = game:GetService("DataStoreService") local dataStore = dataStoreService:GetDataStore("Coins") game.Players.PlayerAdded:Connect(function(Player) local leaderstats = Instance.new("Folder", Player) leaderstats.Name = "leaderstats" local Checkpoint = Instance.new("IntValue", leaderstats) Checkpoint.Name = "Checkpoint" Checkpoint.Value = 1 local coins = Instance.new("IntValue", leaderstats) coins.Name = "Coins" coins.Value = 0 Player.CharacterAdded:Connect(function(Character) repeat wait() until Player.Character ~= nil local checkpoint = workspace.Checkpoints:FindFirstChild(Checkpoint.value) Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(checkpoint.Position + Vector3.new(0, 2, 0)) end) end) local received,failed = pcall(function() data = dataStore:GetAsync("User-"..Player.UserId) end) if received then coins.Value = data[1] print("Data was recieved.") else print("Data was not received.") end while true do wait(30) dataStore:SetAsync("User-"..Player.UserId, {coins.Value}) end game.Players.PlayerRemoving:Connect(function(Player) local leaderboard = Player.Leaderboard local coins = leaderboard.coins local saved,failed = pcall(function() dataStore:SetAsync("User-"..Player.UserId,{coins.Value}) end) if saved then print("Data was saved successfully.") else print("Data was not saved successfully.") end end)
You need to open the published game in order to have access to the datastore or republish the game. I am thinking you are opening the local game file. You are probably getting an error that says you need to publish; if not let me know.