Answered by
0x5y 105
2 years ago Edited 2 years ago
Okay okay, where to start where to start...
First and foremost you should be using one datastore, and one key for each user. Secondly, you are not separating out each player when you save/load their stats.
I have rewritten your script to suit the above.
Please bear in mind, this code is 100% untested so modification may be necessary.
01 | local datastore = game:GetService( "DataStoreService" ) |
02 | local mutliplierDatastore = datastore:GetDataStore( "Multipliers" ) |
04 | game.Players.PlayerAdded:Connect( function (player) |
07 | local success, errorMessage = pcall ( function () |
08 | playerData = multipliers:GetAsync( tostring (player.UserId)) |
12 | local CoilsMultiplier = Instance.new( "IntValue" ); |
13 | CoilsMultiplier.Name = "CoilsMultiplier" ; |
14 | CoilsMultiplier.Parent = player; |
16 | local CoinsMultiplier = Instance.new( "IntValue" ); |
17 | CoinsMultiplier.Name = "CoinsMultiplier" ; |
18 | CoinsMultiplier.Parent = player; |
20 | local PetLuckMultiplier = Instance.new( "IntValue" ); |
21 | PetLuckMultiplier.Name = "PetLuckMultiplier" ; |
22 | PetLuckMultiplier.Parent = player; |
24 | local CoilsCost = Instance.new( "IntValue" ); |
25 | CoilsCost.Name = "CoilsCost" ; |
26 | CoilsCost.Parent = player; |
28 | local CoinsCost = Instance.new( "IntValue" ); |
29 | CoinsCost.Name = "CoinsCost" ; |
30 | CoinsCost.Parent = player; |
32 | local PetLuckCost = Instance.new( "IntValue" ); |
33 | PetLuckCost.Name = "PetLuckCost" ; |
34 | PetLuckCost.Parent = player; |
36 | if success and playerData ~ = nil then |
37 | print ( "Success, loaded multipliers" ) |
40 | CoilsMultiplier.Value = playerData [ "CoilsMultiplier" ] or 1 |
41 | CoinsMultiplier.Value = playerData [ "CoinsMultiplier" ] or 1 |
42 | PetLuckMultiplier.Value = playerData [ "PetLuckMultiplier" ] or 1 |
43 | CoilsCost.Value = playerData [ "CoilsCost" ] or 100 |
44 | CoinsCost.Value = playerData [ "CoinsCost" ] or 100 |
45 | PetLuckCost.Value = playerData [ "PetLuckCost" ] or 1000 |
49 | CoilsMultiplier.Value = 1 |
50 | CoinsMultiplier.Value = 1 |
51 | PetLuckMultiplier.Value = 1 |
54 | PetLuckCost.Value = 1000 |
60 | game.Players.PlayerRemoving:Connect( function (player) |
63 | playerData [ "CoilsMultiplier" ] = player.CoilsMultiplier.Value |
64 | playerData [ "CoinsMultiplier" ] = player.CoinsMultiplier.Value |
65 | playerData [ "PetLuckMultiplier" ] = player.PetLuckMultiplier.Value |
66 | playerData [ "CoilsCost" ] = player.CoilsCost.Value |
67 | playerData [ "CoinsCost" ] = player.CoinsCost.Value |
68 | playerData [ "PetLuckCost" ] = player.PetLuckCost.Value |
72 | local success, errorMessage = pcall ( function () |
73 | mutliplierDatastore:SetAsync( tostring (player.UserId), playerData) |
77 | print ( "Saved Data Successfully" ) |
84 | game:BindToClose( function () |