Hello! I was creating pet GUI, but there is problem and it won’t save at all.
What do you want to achieve? Keep it simple and clear!
I want it save my everything pet saved on datastore.
What is the issue? Include screenshots / videos if possible!
When I got cat pet like this. We got it but lets try rejoin.
Then
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes I looked developer hub, it was just simple things that I know. I am confused.
Here is datastore script.
local DataStoreService = game:GetService("DataStoreService")
local ds4 = DataStoreService:GetDataStore("Datastore4")
game.Players.PlayerAdded:Connect(function(player)
wait(3)
local PetsFrame = player:FindFirstChild("PlayerGui").MainGui.Pets
PetsFrame.CatButton.Value.Value = ds4:GetAsync(player.UserId) or 0
PetsFrame.NoobButton.Value.Value = ds4:GetAsync(player.UserId) or 0
PetsFrame.DogButton.Value.Value = ds4:GetAsync(player.UserId) or 0
PetsFrame.CatButton.Value.Value = ds4:SetAsync(player.UserId, PetsFrame.CatButton.Value.Value)
PetsFrame.NoobButton.Value.Value = ds4:SetAsync(player.UserId, PetsFrame.NoobButton.Value.Value)
PetsFrame.DogButton.Value.Value = ds4:SetAsync(player.UserId, PetsFrame.DogButton.Value.Value)
while true do
PetsFrame.CatButton.Value.Value = ds4:SetAsync(player.UserId, PetsFrame.CatButton.Value.Value)
PetsFrame.NoobButton.Value.Value = ds4:SetAsync(player.UserId, PetsFrame.NoobButton.Value.Value)
PetsFrame.DogButton.Value.Value = ds4:SetAsync(player.UserId, PetsFrame.DogButton.Value.Value)
print("Sync Successful!")
wait(30)
end
end)
Reminder, Its not just button. I looked my button values and still dont get value just 0 value.
I believe(eaisly could be wrong) you dont need this:
PetsFrame.CatButton.Value.Value = ds4:SetAsync(player.UserId, PetsFrame.CatButton.Value.Value)
PetsFrame.NoobButton.Value.Value = ds4:SetAsync(player.UserId, PetsFrame.NoobButton.Value.Value)
PetsFrame.DogButton.Value.Value = ds4:SetAsync(player.UserId, PetsFrame.DogButton.Value.Value)
--And you can just Replace it with this
ds4:SetAsync(player.UserId, PetsFrame.CatButton.Value.Value)
ds4:SetAsync(player.UserId, PetsFrame.NoobButton.Value.Value)
ds4:SetAsync(player.UserId, PetsFrame.DogButton.Value.Value)
Just going to stay right now that you’re going to inevitably experience throttling and unexpected values if you use DataStores like this. Always try to limit how much you do with DataStores, use them wisely.
You’re using one DataStore with one key and setting different values on that key. The SetAsyncs are going to fail due to attempting to write to the same key within 6 seconds of each other. You should be opting to use a table instead of separate DataStores per value.
Check this article for more information:
If you want a utility that can help you, look into DataStore2 and especially the Combine feature. It’ll allow you to basically do the same thing you’re doing now, except provide some internal utility and handle batching the values of the keys into one dataset for you.
No, don’t change the keys to be different because you might end up making that global (unless you append the UserId). Use a table and one key for the player. Please review my advice, changing the keys used will not be sufficient enough to resolve the data problems you’ll run into.
Building off of what @colbert2677 said, here is a better way to do what you are doing. DataStore2 is not needed in this example.
Data = MyDataStore:GetAsync(12345) or {} --MyInfo is a table of data
SomePlayer.Points = Data.Points or 0
SomePlayer.Money = Data.Money or 0
--now player is leaving
SaveData = {}
SaveData.Points = SomePlayer.Points
SaveData.Money = SomePlayer.Money
MyDataStore:SetAsync(12345, SaveData)
Looks like colbert2677 sloved my problem. Thanks so much!!!
By the way I used this.
local ds4 = DataStoreService:GetDataStore("Datastore4")
local ds5 = DataStoreService:GetDataStore("Datastore5")
local ds6 = DataStoreService:GetDataStore("Datastore6")
Not what I meant either. Please read my posts carefully. I said that you should be using one DataStore and one key, whereas the value you pass is a table given all the elements you’re wanting to save in a dictionary format. You should do some research on this practice to see how you can accomplish it.