Issues with datastore

Hello!
I am trying to make 3 datastores that will store the current exp number value, blue frame X scale size and a variable named “MaxExp”.

Server script in ServerScriptServices:
local DataStoreService = game:GetService(“DataStoreService”)

local DsBlueSize = DataStoreService:GetDataStore("BlueSize")

local DsCurrentExp = DataStoreService:GetDataStore("CurrentExp")

local DsMaxExp = DataStoreService:GetDataStore("MaxExp")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DataStoreFunction = ReplicatedStorage.Remote.DataStore
    DataStoreFunction.OnServerEvent:Connect(function(Player, XPosition, CurrentExpValue, MaxExp)
    	DsBlueSize:UpdateAsync(Player.UserId, function(oldValue)
            local newValue = oldValue or 0.017
    		newValue = XPosition
            return newValue
        end)
    	DsCurrentExp:UpdateAsync(Player.UserId, function(oldValue)
            local newValue = oldValue or 0
    		newValue = CurrentExpValue
            return newValue
        end)
    	DsMaxExp:UpdateAsync(Player.UserId, function(oldValue)
            local newValue = oldValue or 120
    		newValue = MaxExp
            return newValue
        end)
    end)





    game.Players.PlayerAdded:Connect(function(Player)
    	local BlueXSize = DsBlueSize:GetAsync(Player.UserId) or 0.017
    	local CurrentExpToPass = DsCurrentExp:GetAsync(Player.UserId) or 0
    	local MaxExpToPass = DsMaxExp:GetAsync(Player.UserId) or 120
    	
    	print(Player)
    	print(BlueXSize)
    	print(CurrentExpToPass)
    	print(MaxExpToPass)
    	Player.PlayerGui:WaitForChild("EXPBarUP"):WaitForChild("CurrentExp").Value = CurrentExpToPass

    	DataStoreFunction:FireClient(Player, BlueXSize, CurrentExpToPass, MaxExpToPass)
    end)

Local script in the GUI:
game.Players.PlayerRemoving:Connect(function()

DataStoreFunction:FireServer(Player, Blue.Size.X.Scale, CurrentExp.Value, MaxExp)

end)

DataStoreFunction.OnClientEvent:Connect(function(Player, BlueSizeTransfer, CurrentExpTransfer, MaxExpValue)

Blue.Size = UDim2.new(BlueSizeTransfer, Blue.Size.X.Offset, Blue.Size.Y.Scale, Blue.Size.Y.Offset)

local MaxExp = MaxExpValue

end)

No errors at all.
It just keeps printing when a new player joins:
Araxon
0.017
0
120

where is SetAsync? i cant see what u r setting ur only getting the data

1 Like

I am using UpdateAsync… I was told that SetAsync is the worse way to save datastores.

First off, you should not be using 3 data stores for three values in the same script. Save BlueSize, CurrentExp and MaxExp in a table so that you don’t clog up the DataStore requests (as you can only make so many.)

Give me a minute to take a closer look at these.

1 Like

Agreed, but if you use UpdateAsync add PlayerRemoving Event

Okay, but is it really the source of the problem with the datastores?

No it is not! u have not put a player removing event

1 Like

There is a PlayerRemoving event in the local script…

I don’t think so, not unless you receive orange warning messages about sending fewer requests.

1 Like

its in a client it only saves in the client not the server

No warnings at all, I can do that but I don’t think it will solve the problem.

There is a PlayerRemoving event which fires the RemoteEvent to the server script…
Please take a closer look at both of the scripts.

3 Data Stores Are Bad To Save!

also where is your leaderstats

1 Like

When using scripting support, people don’t provide either whole scripts or other scripts. They expect others to know that leaderstats are stored in a folder under player.

With this being said, if there was an issue with leaderstats than it would return an error.

1 Like

I didn’t use a leaderstat, “CurrentExp” is a number value inside the GUI.

i recommend a players name if its a value

1 Like

DataStoreFunction:FireServer(Player…

Don’t :FireServer with player, as it gets sent automatically as the first variable.

1 Like

Okay, I will try that, also while trying to change it to a single datastore using a table I got this error.
` local BlueSize = AllDataStores:GetAsync(Player.UserId)[1] or 0.017

[ServerScriptService.DataStoreRemote:26: attempt to index nil with number]

How do I exactly take it from an array?

you could just make variables and pcall them with the values get async the variable i meant the value inside the var

and check if there data is nil or not

1 Like

But the data will always be a value, because if it won’t get the sync it will be 0, 0.017 or 120…