I am creating a game and i really needed a a savable leaderboard i finally found one but since i started using it this error message came up saying i have to break or kill the script and its crashing roblox studio.
01 | local datastore = game:GetService( "DataStoreService" ) |
02 | local ds 1 = datastore:GetDataStore( "GemSaveSystem" ) |
03 | local ds 2 = datastore:GetDataStore( "CashSaveSystem" ) |
04 |
05 | game.Players.PlayerAdded:connect( function (plr) |
06 | local folder = Instance.new( "Folder" , plr) |
07 | folder.Name = "leaderstats" |
08 | local gems = Instance.new( "IntValue" , folder) |
09 | gems.Name = "Gems" |
10 | local cash = Instance.new( "IntValue" , folder) |
11 | cash.Name = "Cash" |
12 |
13 | gems.Value = ds 1 :GetAsync(plr.UserId) or 0 |
14 | ds 1 :SetAsync(plr.UserId, gems.Value) |
15 |
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?
The reason your script is crashing is because without a wait() it lets the script run a lot of times very quickly which will cause studio to crash so you will need to add a wait into it somewhere like this:
01 | local datastore = game:GetService( "DataStoreService" ) |
02 | local ds 1 = datastore:GetDataStore( "GemSaveSystem" ) |
03 | local ds 2 = datastore:GetDataStore( "CashSaveSystem" ) |
04 |
05 | game.Players.PlayerAdded:connect( function (plr) |
06 | local folder = Instance.new( "Folder" , plr) |
07 | folder.Name = "leaderstats" |
08 | local gems = Instance.new( "IntValue" , folder) |
09 | gems.Name = "Gems" |
10 | local cash = Instance.new( "IntValue" , folder) |
11 | cash.Name = "Cash" |
12 |
13 | gems.Value = ds 1 :GetAsync(plr.UserId) or 0 |
14 | ds 1 :SetAsync(plr.UserId, gems.Value) |
15 |
If this doesn't work, I didn't try it so.