I've tried getting the arguments right in the methods :GetAsync() and :SetAsync() but nothing new happens like it doesn't save. I don't know if my arguments are wrong or what, no error occurs either. Any help?
01 | -----Saving |
02 | game.Players.PlayerRemoving:connect( function (plr) |
03 | local Data = game:GetService( "DataStoreService" ) |
04 | local button = workspace.PartTwo:FindFirstChild( "SurfaceGui" ).Frame:WaitForChild( "Button" ) |
05 | -----Name |
06 | Data:GetDataStore( "SaveApplication" ) |
07 | -----Save |
08 | while wait( 3 ) do |
09 | Data:SetAsync( "Keysave" ,button) |
10 | end |
11 | end ) |
12 | ------Loading |
13 | game.Players.PlayerAdded:connect( function (plr) |
14 | local Data = game:GetService( "DataStoreService" ) |
15 | local button = workspace.PartTwo:FindFirstChild( "SurfaceGui" ).Frame:WaitForChild( "Button" ) |
16 | -----Name |
17 | Data:GetDataStore( "SaveApplication" ) |
18 | -----Save |
19 | Data:GetAsync( "Keysave" ,button) |
20 | end ) |
You cannot save instances directly to ROBLOX DataStores. However, you can save the parameters of the TextButton.
For example, the position and text. An example of saving text, is
1 | Data:SetAsync( "Keysave" , button.Text) |
When a player joins another server, you can have the script create the TextButton and apply the DataStore's values.