Can anyone help? Datastore script seems to add a level every time the player leaves and rejoins.
Asked by
5 years ago Edited 5 years ago
Yo, so my datastore script seems to have this issue where instead of saving the players level and exp, it for some reason jumps a level or two sometimes?? (for example: the players level would be 1, then once they leave and rejoin it becomes 2?)
Here is the code if anyone wants to know;
01 | local DSService = game:GetService( "DataStoreService" ):GetDataStore( "-test#1222" ) |
02 | local RunService = game:GetService( "RunService" ) |
04 | game.Players.PlayerAdded:Connect( function (plr) |
05 | local uniquekey = 'id-' ..plr.userId |
06 | local leaderstats = Instance.new( "Folder" , plr) |
07 | local Level = Instance.new( "NumberValue" ) |
08 | local EXP = Instance.new( "NumberValue" ) |
09 | local MaxEXP = Instance.new( "NumberValue" ) |
10 | local Cash = Instance.new( "NumberValue" ) |
11 | local FactionEXP = Instance.new( "NumberValue" ) |
13 | local Strength = Instance.new( "NumberValue" ) |
14 | local Stamina = Instance.new( "NumberValue" ) |
15 | local Defence = Instance.new( "NumberValue" ) |
16 | local Quirk = Instance.new( "NumberValue" ) |
17 | local Points = Instance.new( "NumberValue" ) |
19 | local New = Instance.new( "BoolValue" ) |
21 | leaderstats.Name = "Data" |
23 | Level.Parent = leaderstats |
24 | EXP.Parent = leaderstats |
25 | MaxEXP.Parent = leaderstats |
26 | Cash.Parent = leaderstats |
27 | FactionEXP.Parent = leaderstats |
28 | New.Parent = leaderstats |
30 | Strength.Parent = leaderstats |
31 | Stamina.Parent = leaderstats |
32 | Defence.Parent = leaderstats |
33 | Quirk.Parent = leaderstats |
34 | Points.Parent = leaderstats |
38 | MaxEXP.Name = "MaxEXP" |
40 | FactionEXP.Name = "FactionEXP" |
42 | Strength.Name = "Strength" |
43 | Stamina.Name = "Stamina" |
44 | Defence.Name = "Defence" |
46 | Points.Name = "Points" |
64 | local GetSaved = DSService:GetAsync(uniquekey) |
67 | Level.Value = GetSaved [ 1 ] |
68 | EXP.Value = GetSaved [ 2 ] |
69 | Cash.Value = GetSaved [ 3 ] |
70 | FactionEXP.Value = GetSaved [ 4 ] |
71 | New.Value = GetSaved [ 5 ] |
73 | Strength.Value = GetSaved [ 6 ] |
74 | Stamina.Value = GetSaved [ 7 ] |
75 | Defence.Value = GetSaved [ 8 ] |
76 | Quirk.Value = GetSaved [ 9 ] |
77 | EXP.Value = GetSaved [ 10 ] |
78 | Points.Value = GetSaved [ 11 ] |
80 | local NumberFS = { Level.Value,EXP.Value,Cash.Value,FactionEXP.Value,New.Value,Strength.Value,Defence.Value,Quirk.Value,Stamina.Value,MaxEXP.Value,Points.Value, } |
81 | DSService:SetAsync(uniquekey,NumberFS) |
92 | game.Players.PlayerRemoving:Connect( function (plr) |
93 | local uniquekey = "id-" ..plr.userId |
94 | local SaveTable = { plr.Data.Level.Value,plr.Data.EXP.Value,plr.Data.Cash.Value,plr.Data.FactionEXP.Value,plr.Data.New.Value,plr.Data.Strength.Value,plr.Data.Defence.Value,plr.Data.Stamina.Value,plr.Data.Quirk.Value,plr.Data.MaxEXP.Value,plr.Data.Points.Value } |
95 | DSService:SetAsync(uniquekey, SaveTable) |