Answered by
6 years ago Edited 6 years ago
A datastore is what you use to save things. Example;
Say I want to save levels in a game I'd first create a folder and parent it to something.
Then I'd create an instance.new of a intvalue for the level and put it inside the folder.
Here's an example that would load on join and save on leave.
01 | local player = game:GetService( "Players" ) |
02 | local SS = game:GetService( "ReplicatedStorage" ) |
03 | local DS = game:GetService( "DataStoreService" ) |
08 | [ "Level" ] = DS: GetDataStore( "Level" ) |
11 | player.PlayerAdded:connect( function (plr) |
13 | local success, err = pcall ( function () |
14 | local userID = plr.userId |
16 | local stats = Instance.new( "Folder" ) |
20 | local Level = Instance.new( "IntValue" ) |
23 | Level.Value = data [ "Level" ] :GetAsync(userID) or "1" |
25 | if success then print ( "Success" ) |
29 | player.PlayerRemoving:connect( function (plr) |
30 | local userID = plr.userId |
31 | local stats = plr:WaitForChild( "Stats" ) |
32 | data [ "Level" ] :SetAsync(userID, stats.Level.Value) |
Hoped this made sense or helped, I'm kind of new to scripting too