Araxon
(Araxon)
April 13, 2020, 11:45am
#1
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
FerbZides
(FerbZides)
April 13, 2020, 11:58am
#2
where is SetAsync? i cant see what u r setting ur only getting the data
1 Like
Araxon
(Araxon)
April 13, 2020, 11:59am
#3
I am using UpdateAsync… I was told that SetAsync is the worse way to save datastores.
CAP7A1N
(Cap)
April 13, 2020, 11:59am
#4
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
FerbZides
(FerbZides)
April 13, 2020, 12:00pm
#5
Agreed, but if you use UpdateAsync add PlayerRemoving Event
Araxon
(Araxon)
April 13, 2020, 12:00pm
#6
Okay, but is it really the source of the problem with the datastores?
FerbZides
(FerbZides)
April 13, 2020, 12:00pm
#7
No it is not! u have not put a player removing event
1 Like
Araxon
(Araxon)
April 13, 2020, 12:00pm
#8
There is a PlayerRemoving event in the local script…
CAP7A1N
(Cap)
April 13, 2020, 12:00pm
#9
I don’t think so, not unless you receive orange warning messages about sending fewer requests.
1 Like
FerbZides
(FerbZides)
April 13, 2020, 12:01pm
#10
its in a client it only saves in the client not the server
Araxon
(Araxon)
April 13, 2020, 12:01pm
#11
No warnings at all, I can do that but I don’t think it will solve the problem.
Araxon
(Araxon)
April 13, 2020, 12:02pm
#12
There is a PlayerRemoving event which fires the RemoteEvent to the server script…
Please take a closer look at both of the scripts.
FerbZides
(FerbZides)
April 13, 2020, 12:06pm
#13
3 Data Stores Are Bad To Save!
also where is your leaderstats
1 Like
CAP7A1N
(Cap)
April 13, 2020, 12:07pm
#14
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
Araxon
(Araxon)
April 13, 2020, 12:08pm
#15
I didn’t use a leaderstat, “CurrentExp” is a number value inside the GUI.
FerbZides
(FerbZides)
April 13, 2020, 12:09pm
#16
i recommend a players name if its a value
1 Like
CAP7A1N
(Cap)
April 13, 2020, 12:09pm
#17
DataStoreFunction:FireServer(Player…
Don’t :FireServer with player, as it gets sent automatically as the first variable.
1 Like
Araxon
(Araxon)
April 13, 2020, 12:11pm
#18
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?
FerbZides
(FerbZides)
April 13, 2020, 12:12pm
#19
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
Araxon
(Araxon)
April 13, 2020, 12:13pm
#20
But the data will always be a value, because if it won’t get the sync it will be 0, 0.017 or 120…