Answered by
5 years ago Edited 5 years ago
Use a table. It's so much cleaner compared to using different keys.
I've fixed your code:
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local DataStoreVersion = 10 |
03 | local DataStore = DataStoreService:GetDataStore( "DataStorex" ..DataStoreVersion) |
05 | game.Players.PlayerAdded:Connect( function (Player) |
06 | local Stats = Instance.new( "Folder" ,Player) |
09 | local Strength = Instance.new( "IntValue" ,Stats) |
10 | Strength.Name = "Strength" |
12 | local Defense = Instance.new( "IntValue" ,Stats) |
13 | Defense.Name = "Defense" |
15 | local Energy = Instance.new( "IntValue" ,Stats) |
16 | Energy.Name = "Energy" |
18 | local Speed = Instance.new( "IntValue" ,Stats) |
21 | local Rebirths = Instance.new( "IntValue" ,Stats) |
22 | Rebirths.Name = "Rebirths" |
29 | local DataStoreReturned = DataStore:GetAsync(Player.UserId) |
30 | loadedstrength = DataStoreReturned.Strength |
31 | loadeddefense = DataStoreReturned.Defense |
32 | loadedenergy = DataStoreReturned.Energy |
33 | loadedspeed = DataStoreReturned.Speed |
34 | loadedrebirths = DataStoreReturned.Rebirths |
36 | Strength.Value = loadedstrength |
37 | Defense.Value = loadeddefense |
38 | Energy.Value = loadedenergy |
39 | Speed.Value = loadedspeed |
40 | Rebirths.Value = loadedrebirths |
42 | game.Players.PlayerRemoving:connect( function (player) |
43 | DataStore:SetAsync(plyr.UserId, { |
44 | Strength = Player.Stats.Strength.Value |
45 | Defense = Player.Stats.Defense.Value |
46 | Energy = Player.Stats.Energy.Value |
47 | Speed = Player.Stats.Speed.Value |
48 | Rebirths = Player.Stats.Rebirths.Value |
Also, since you said you were having trouble with tables, heres a very simple example:
if you type value.TableValue1 it will be "test"