DataStore doesn't spit out any errors and wont save

Screenshot_1089

Anybody tell me why it won’t work? Thanks.

local DataStore = game:GetService(“DataStoreService”)
local DataStorage = DataStore:GetDataStore(“StockStorage”)

game.Players.PlayerAdded:Connect(function(player)
pcall(function()

	local DataStorage = Instance.new("Folder", game.ServerStorage.DataStorage)
	DataStorage.Name = player.Name
	
	local PlayerStorage = game.ServerStorage.DataStorage:FindFirstChild(player.Name)
	
	local Currency = Instance.new("Folder", PlayerStorage)
	Currency.Name = "PlayerCurrency"
	
	local AUD = Instance.new("IntValue", Currency)
	AUD.Name = "AUD"
	
	local StockDirectory = game.ServerStorage.StockDirectory
	local DataDirectory = StockDirectory:Clone()
	
	DataDirectory.Parent = PlayerStorage
	
	DataStorage:GetAsync(player.UserId, DataStorage.PlayerCurrency.AUD.Value)
	
	local LoadingData = DataStorage:GetAsync(player.UserId)
	
	if LoadingData then
		
		for i,v in pairs(DataDirectory:GetChildren()) do
			
			v.Value = LoadingData[v.Name]
			
		end
	end
end)

end)

game.Players.PlayerRemoving:Connect(function(player)

local PlayerData = game.ServerStorage.DataStorage:FindFirstChild(player.Name)

if PlayerData then
	
	local DataSaved = {}	
	
	for i,v in pairs(PlayerData.StockDirectory:GetChildren()) do
		
		DataSaved[v.Name] = v.Value
		
	end
	
	DataStorage:SetAsync(player.UserId, DataSaved)
	DataStorage:SetAsync(player.UserId, PlayerData.PlayerCurrency.AUD.Value)

end

end)

1 Like

No, because that’s not the purpose of this category. Don’t dump all your code here and expect anyone to help you resolve your issue, especially when there isn’t any indication of where an error may be and no indication that you’ve attempted to apply basic debugging before posting this question.

Confer with About the Scripting Support category for an understanding of how this category should be used. Follow the category guidelines, apply some basic debugging and do a bit of searching or tinkering before posting a thread. Include as much detail as you can instead of throwing your assets on a thread and asking for someone to resolve your issue for you.

2 Likes

Bro, chill. I spent 25 minutes with different debugging methods. I tried my best but I clearly can’t find the solution, I’m trying to see if someone can recreate it and see why it won’t work. It should work but it clearly doesn’t. Please don’t be one of those kids who have nothing to do in their life and just keyboard warrior everyone. Now, can you help me figure out the problem? I’m using another method and still no information on output or anything.

1 Like

Could you explain what debugging methods you tried and how they didn’t prove to be successful? A lack of given information leaves a whole in understanding what you’ve tried so far and to what degree of success that’s had. “It doesn’t work” isn’t sufficient enough for any thread in this category: details are required.

You should also calm down wrt passive aggressiveness in your response. Follow the category guidelines or don’t post threads to this category. This is not a venue for you to dump assets and ask for your problems to be solved for you.

2 Likes

Okay, Listen here my dude. I’ve tried loading the saving the data every 60 seconds, no output error there. I tried loading the data every 60 seconds, also no output error there. The current thing I’m trying to do is save and load data with a different script on the same data store but no errors once again. Also, you are the one who offended me first with your aggressiveness, treat others like the way you want to be treated. Don’t expect someone not to be aggressive to them when your the one who did it first. Fix your tone and talk more friendly then you may actually help people out.

1 Like

Maybe you aren’t getting errors because your code is wrapped in a pcall??? Also you are overwriting a Datastore when saving, I don’t see why you have a DataSaved table if you aren’t going to use it.

2 Likes

You have a very simple oversight in your code which you can identify by applying basic debugging. Changing your autosave interval isn’t basic debugging; I’m talking about things like prints and breakpoints. Your response already indicates that you haven’t really tried fixing this yourself first.

Telling you not to abuse the category is not offensive or aggressive. Don’t post here if you can’t be bothered to read the forum rules or category guidelines. This category is not for you to dump code and expect fixes to come to you.

3 Likes

Thanks my dude, it was the overwriting that was the problem. Thanks a lot!

Please be as detailed as possible when describing your problem in support categories!