Why isn't my table in DataStore saving?
Asked by
4 years ago Edited 4 years ago
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local DataStore = DataStoreService:GetDataStore( "coinsDataStore" ) |
04 | game.Players.PlayerAdded:Connect( function (plr) |
06 | local success,errormessage = pcall ( function () |
07 | data = DataStore:GetAsync(plr.UserId.. "-data" ) |
20 | local leaderstats = Instance.new( "Folder" ,plr) |
21 | leaderstats.Name = "leaderstats" |
23 | local checkpoints = Instance.new( "IntValue" ,leaderstats) |
24 | checkpoints.Name = "Stage" |
26 | checkpoints.Value = data [ 2 ] |
30 | local coins = Instance.new( "IntValue" ,leaderstats) |
40 | plr.CharacterAdded:Connect( function (Character) |
41 | repeat wait() until plr.Character ~ = nil |
42 | local checkpoint = workspace.Stages:FindFirstChild(checkpoints.Value) |
43 | Character:WaitForChild( "HumanoidRootPart" ).CFrame = CFrame.new(checkpoint.Position + Vector 3. new( 0 , 2 , 0 )) |
47 | game.Players.PlayerRemoving:Connect( function (plr) |
49 | local checkpoints = plr.leaderstats.Stage.Value |
50 | local coins = plr.leaderstats.Coins.Value |
51 | local data = { coins,checkpoints } |
52 | local success,errormessage = pcall ( function () |
53 | DataStore:SetAsync(plr.UserId.. "-data" ,data) |
I am trying to get the datastore but it seems it doesn't load in. I have API services in Studio.