Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i solve this loading from datastore issue?

Asked by 2 years ago

i have a multipliers shop that basically multiplies the amount of x the player earns when they collect an item ( coins, etc) but when it saves the data it saves to the player properly, however the loading portion is the messed up part. It loads into rep storage and for the first player thats great however when theres more than 1 player it messes up and replicates the first player's multipliers to everyone else. Should i save a value to a table and then set it to the bool value? where would that bool value end up? in rep storage, server storage, or the player themselves? i have alot of unknowns when making this script, i wanted to tackle a harder script for myself but i think i bit off more than i can chew

001local replicatedstorage = game:GetService("ReplicatedStorage")
002local remotecoins = replicatedstorage.Multipliers.CoinsMultiplier
003local remotecoils = replicatedstorage.Multipliers.CoilsMultiplier
004local remotepetluck = replicatedstorage.Multipliers.PetLuckMultiplier
005local datastore = game:GetService("DataStoreService")
006local multipliers = datastore:GetDataStore("Multipliers")
007 
008game.Players.PlayerAdded:Connect(function(player)
009    local data1
010    local data2
011    local data3
012    local data4
013    local data5
014    local data6
015 
View all 107 lines...

any help would be great, im just hoping that the problem isnt too great and its something small like what i mention in terms of it being just replacing what the value is saved to and where.

0
You may have to store your values into a table value like ``local data = []`` Xx_ashcarter13 17 — 2y

1 answer

Log in to vote
1
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.

01local datastore = game:GetService("DataStoreService")
02local mutliplierDatastore = datastore:GetDataStore("Multipliers")
03 
04game.Players.PlayerAdded:Connect(function(player)
05    local playerData
06 
07    local success, errorMessage = pcall(function()
08        playerData = multipliers:GetAsync(tostring(player.UserId))
09        print(playerData)
10    end)
11 
12    local CoilsMultiplier = Instance.new("IntValue");
13    CoilsMultiplier.Name = "CoilsMultiplier";
14    CoilsMultiplier.Parent = player;
15 
View all 86 lines...
0
im having an error that i cant seem to figure out im getting the error (ServerScriptService.MultipliersHandler:40: attempt to index nil with 'CoilsMultiplier') it breaks like that the first time, if i load in again before wiping the datastore info, it loads me in with 0 multipliers. De_Bosnian 7 — 2y
0
For some reason, `playerData` is nil. When it gets printed on line 9 and line 38, what does it print? The error is likely due to something on my part, where I did not check if `playerData` actually exists, causing your error. I have edited my post to check for that. Let me know if it works. 0x5y 105 — 2y
Ad

Answer this question