What do you want to achieve? i want two leaderstats (Cash and Kills) but only want to save Cash, is that possible?
What is the issue? everything saves right now
What solutions have you tried so far? i looked for it on the internet and tried figuring it out myself
local DSService = game:GetService("DataStoreService")
local Data1 = DSService:GetDataStore("killsDataStore_1")
local Data2 = DSService:GetDataStore("cashDataStore_1")
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = "id-"..plr.userId
local leaderstats = Instance.new("Folder", plr)
local savevalue1 = Instance.new("IntValue")
local savevalue2 = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
savevalue1.Parent = leaderstats
savevalue1.Name = "Kills"
savevalue1.Value = Data1:GetAsync(uniquekey)
savevalue2.Parent = leaderstats
savevalue2.Name = "Cash"
savevalue2.Value = Data2:GetAsync(uniquekey)
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = "id-"..plr.userId
Data1:SetAsync(uniquekey, plr.leaderstats.Kills.Value)
Data2:SetAsync(uniquekey, plr.leaderstats.Cash.Value)
end)
1 Like
Use a table to SetAsync() there, your script should be good.
– remove data2
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = “id-”…plr.userId
Data1:SetAsync(uniquekey, plr.leaderstats.Kills.Value)
end)
1 Like
– to save Cash, remove data1
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = “id-”…plr.userId
Data2:SetAsync(uniquekey, plr.leaderstats.Cash.Value)
end)
Like I said, use a table. Table’s will gather multiple things instead of one, that’s how to fix this problem.
also remove these…
savevalue1.Name = “Kills”
savevalue1.Value = Data1:GetAsync(uniquekey)
replace with this…
savevalue1.Value = 0
PrizeCounterPuncher:
– to save Cash, remove data1
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = “id-”…plr.userId
Data2:SetAsync(uniquekey, plr.leaderstats.Cash.Value)
end)
He want’s two too save. Not one.
PrizeCounterPuncher:
– remove data2
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = “id-”…plr.userId
Data1:SetAsync(uniquekey, plr.leaderstats.Kills.Value)
end)
Same thing, If you’re gonna make a solution dont backforce and do something you know they dont want.
Instead, use a table.
DasKairo
(Cairo)
February 14, 2023, 4:05pm
#8
God this Data Store is a mess.
You should Instead have a Data Store where you have a Table of information, this would be making 2 DataStores for each Player, in which you only need ONE, even Roblox recommends you create less Data Stores,
another thing is to wrap your GetAsync
and SetAsync
in a pcall()
, which can vary:
local Success, Data = pcall(function()
return Data1:GetAsync(uniquekey)
end)
-- Method 2:
local Success, Data = pcall(Data1.GetAsync, Data1, uniquekey)
This is so you don’t get errors when getting data as your Data Stores can fail, this would ensure these errors don’t appear, but you would need to check if the pcall()
was a Success, in order to Distribute Data, you should also put your code in a repeat
loop until the Data is found or until it has reached a limit.
You can also create a Table to Store Player Data andManage them better so when the Server Closes, you can Use BindToClose
for the Purpose.
1 Like
I believe he said he wants to save only Cash, but both are being saved.
Same thing I was thinking. I say look at the tutorials and memorize.
look at the title.
“Leaderstats that show 2 leaderstats but only saves one”
also, if you want to remove it. But certainly I think you dont,
Just remove data2 and remove one of the leaderstats you have.
Add onto that, Im sure others agree with me.
DasKairo:
God this Data Store is a mess.
You should Instead have a Data Store where you have a Table of information, this would be making 2 DataStores for each Player, in which you only need ONE, even Roblox recommends you create less Data Stores,
“Tables”
That is what he wants.
Look at the description… " 1. What do you want to achieve? i want two leaderstats (Cash and Kills) but only want to save Cash, is that possible?"
Never assume bro. I just go by what he asked for.
ok just to know, you want 2 values of cash and then kills*, but you only want the cash to be saved?
“Kills” and “cash”
He want’s them both to be saved, not removing data from Kills or Cash. If that was obvious.
I know how to fix this, im not who posted this. This girl / boy think’s that the guy want’s to remove Data of kills / cash.
wait, i thought it was you bruhhhh
Have you ever thought that maybe he thought he needed datastores for the leaderstats to work? If he already knows how to do everything, then would he be asking for our help? Give him a chance to answer the question bro. You don’t need to assume and answer for him.
DasKairo
(Cairo)
February 14, 2023, 4:15pm
#24
@PrizeCounterPuncher @Sea_KidTwelve
Can yall fight in the Message Group I created?
here isnt the place to be doing such
1 Like
sorry bro my code issues rn cant find a way on how to save data store