Answered by
4 years ago Edited 4 years ago
You are saving it to the same datastore, you are trying to put the user into one data store 3 times which is not possible. You need to create a new data store for each value, such as, ds1, ds2, ds3.
Here is the fixed code:
01 | game.Players.PlayerAdded:connect( function (p) |
02 | local WF = Instance.new( "Folder" ) |
03 | WF.Name = "leaderstats" |
06 | local Rocks = Instance.new( "IntValue" ) |
09 | local Wood = Instance.new( "IntValue" ) |
12 | local Strings = Instance.new( "IntValue" ) |
14 | Strings.Name = "Strings" |
18 | local players = game:GetService( "Players" ) |
19 | local datastore = game:GetService( "DataStoreService" ) |
20 | local ds 1 = datastore:GetDataStore( "Materials1" ) |
21 | local ds 2 = datastore:GetDataStore( "Materials2" ) |
22 | local ds 3 = datastore:GetDataStore( "Materials3" ) |
24 | players.PlayerAdded:connect( function (player) |
26 | local folder = player:WaitForChild( "leaderstats" ) |
27 | folder.Name = "leaderstats" |
28 | folder.Parent = player |
30 | local currency 1 = player.leaderstats.Rocks |
31 | currency 1. Name = "Rocks" |
32 | currency 1. Parent = player.leaderstats |
33 | currency 1. Value = ds 1 :GetAsync(player.UserId) or 0 |
34 | ds 1 :SetAsync(player.UserId, currency 1. Value) |
36 | local currency 2 = player.leaderstats.Wood |
37 | currency 2. Name = "Wood" |
38 | currency 2. Parent = player.leaderstats |
39 | currency 2. Value = ds 1 :GetAsync(player.UserId) or 0 |
40 | ds 2 :SetAsync(player.UserId, currency 2. Value) |
42 | local currency 3 = player.leaderstats.Strings |
43 | currency 3. Name = "Strings" |
44 | currency 3. Parent = player.leaderstats |
45 | currency 3. Value = ds 1 :GetAsync(player.UserId) or 0 |
46 | ds 3 :SetAsync(player.UserId, currency 3. Value) |
48 | currency 1. Changed:connect( function () |
49 | ds 1 :SetAsync(player.UserId, currency 1. Value) |
51 | currency 2. Changed:connect( function () |
52 | ds 2 :SetAsync(player.UserId, currency 2. Value) |
55 | currency 3. Changed:connect( function () |
56 | ds 3 :SetAsync(player.UserId, currency 3. Value) |
Be sure to mark as the answer if this helped.