Saving data that is in folders with dss

I have been reading several posts and i am lost as to how i save data in folders. I have a folder in replicated storage called PlayerData then in that folder I want to put every players data in their but I don’t know how to do this with data store. I have a dummy that i can just clone and rename the folder to the player name but there is another folder in that with boolean values that are for the players owned stuff. how do i do this?

2 Likes

Do you want to store boolean values with datastore?

1 Like

yes i want to store boolean values with datastore

is there a way i can create a table for each player and access it later, and use that to save instead of making folders? (also i havent used datastore like ever only once for leaderboard and thats it)

–Lets pretend you have in game cash and your trying to store an integer. You would want a
–script in the server script storage that looks something like this

local DataStoreService = game:GetService(“DataStoreService”)

local myDataStore = DataStoreService:GetDataStore(“1”) – can be any number

game.Players.PlayerAdded:Connect(function(player)
local DataStore = Instance.new(“Folder”)
DataStore.Name = “DataStore”
DataStore.Parent = player

    local Cash = Instance.new("IntValue")
    Cash.Name = "Cash"
    Cash.Parent = DataStore

    local playerUserId = "Player_"..player.UserId
    local data
local success, errormessage = pcall(function()
	data = myDataStore:GetAsync(playerUserId)
	
end)

   if success then 
	if data then
		Cash.Value = data.Cash
	end
end

end
–that will call for datastores, means it wont do anything or leave the value as default. Now
–you need to store the value to the server, lets store it when player exits the game

game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = “Player_”…player.UserId
local data = {
Cash = player.DataStore.Cash.Value;
}
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print(“Success Saving Data”)
else
print(“There was an error saving data”)
warn(errormessage)
end
end)
– If you must have to have an bool, then you can be creative and use 1 as true and 0 as false. Or Instance.new(“BoolValue”) instead

2 Likes

sorry if its really messy i dont know how to add a scrolling frame

1 Like

When you get the data or you don’t. Then you would just create an instance inside the folder and name it to the player and then on playerremoving you can just index through that folder and destroy it so you don’t have a massive folder of playervalues that are no longer needed. I’m assuming this is what you were asking.

1 Like