DataStore script won't save GUI Buttons [STILL UNANSWERED]?
Asked by
6 years ago Edited 6 years ago
I'm trying to make a DataStore script that saves and loads GUI buttons and money; it saves/loads money just fine, but it doesn't save/load the GUI buttons; I think there's a problem with the loading.
SCRIPT:
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local ds = DataStoreService:GetDataStore( "danceSave" ) |
03 | local ds 2 = DataStoreService:GetDataStore( "MoneySave" ) |
05 | game:GetService( "Players" ).PlayerAdded:Connect( function (Player) |
07 | local Stats = Instance.new( 'Folder' ) |
08 | Stats.Name = "leaderstats" |
10 | local Money = Instance.new( 'NumberValue' , Stats) |
20 | local CanSave = Instance.new( 'BoolValue' , Player) |
22 | CanSave.Name = "CanSaveData" |
25 | local DataFetchSuccess, ErrorMessage = pcall ( function () |
26 | moneyData = ds 2 :GetAsync( tostring (Player.UserId)) |
27 | dancesData = ds:GetAsync( tostring (Player.UserId)) |
29 | if DataFetchSuccess then |
30 | if moneyData ~ = nil then |
31 | print ( "Money save found" ) |
32 | Money.Value = moneyData |
34 | print ( "No money save found." ) |
39 | if dancesData ~ = nil then |
41 | for i,v in pairs (dancesData) do |
43 | local Dance = Player.PlayerGui.Dances:FindFirstChild(v) |
45 | Dance:Clone().Parent = Player.PlayerGui.dancesGui.dancesFrame.danceFrame.danceScrolling |
51 | Player.CanSaveData.Value = false |
52 | Player:Kick( "Your data failed to load! Please rejoin." ) |
56 | game:GetService( "Players" ).PlayerRemoving:Connect( function (Player) |
57 | if Player.CanSaveData.Value = = false then return end |
59 | local moneyData = Player.leaderstats.Money.Value |
60 | local dancesToSave = { } |
65 | for i,v in pairs (Player.PlayerGui.dancesGui.dancesFrame.danceFrame.danceScrolling:GetChildren()) do |
67 | if v:IsA( "TextButton" ) then |
68 | table.insert(dancesToSave, v.Name) |
73 | local DataWriteSuccess, ErrorMessage = pcall ( function () |
74 | print ( "Saving " ..Player.Name.. "s stats" ) |
75 | ds:SetAsync( tostring (Player.UserId), dancesToSave) |
77 | ds 2 :SetAsync( tostring (Player.UserId), moneyData) |
81 | if not DataWriteSuccess then |
84 | while Retry_Count < 6 do |
86 | local Succeed, Error = pcall ( function () |
87 | print ( "Attempting to save " ..Player.Name.. "'s stats." ) |
88 | ds:SetAsync( tostring (Player.UserId), dancesToSave) |
89 | ds 2 :SetAsync( tostring (Player.UserId), moneyData) |
91 | if Succeed then print ( "Saved " ..Player.Name.. "'s stats" ) break end |
92 | Retry_Count = Retry_Count + 1 |
There are no errors.