For a game that I am working on I wanted to have a system where the progress players make can be saved using values inserted into a folder located in the player via the starter player scripts. I thought that I would be able to work this out myself but after making several attempts I'm at a loss. If it isn't any trouble for anyone, I would really like to know what I'm doing wrong with this. Any help would be greatly appreciated, here is the script:

local DataStore = game:GetService("DataStoreService")
local ds2 = DataStore:GetDataStore("save data")

game.Players.PlayerAdded:connect(function(player)
	wait()
	local leader = player.PlayerScripts.Saves
	local Mining = player.PlayerScripts.Saves
	ds2:GetAsync(player.UserId).parent = Mining or Instance.new("Part")
	ds2:SetAsync(player.UserId,leader:getChildren())
	Mining.Changed:connect(function()
		print('Saving Data')
		ds2:SetAsync(player.UserId,leader:getChildren())
		print("Saved")
		
	end)
end)

5 comments

0

I'm a bit loss, what's leader and Mining for? You're loading and saving at the same time, but I just still can't understand the code. It's also best not to use the Changed event, as you can throttle Data Stores. Use a loop instead, and add a wait(200) .

0

Before doing anything, I'd consider reading those two guides. They helped me, and they should help you too.

0

Like the guy in here, I don't full understand the code either, I'm was assuming leader and Mining were two different values, but in your code you used "leader:getChildren()", so It'd be nice if you could clarify what you meant when you wrote that code.

0

dont store it locally or exploiters will be able to change their stats easily