Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

DataStore is not saving Data how to fix that?

I don't know where's my problem.

I wanted to make when player is leaving and if he have items then all items will be saved like Table in Datastore. But I'm checking DataStore that's not saving.

Code: (Server Script)

local DSS = game:GetService("DataStoreService"):GetDataStore("NewDStestq312")
local RS = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:Connect(function(Player)
	local Folder = Instance.new("Folder",RS)
	Folder.Name = Player.Name.."-Inventory.UID-"..Player.UserId
	local getData = DSS:GetAsync(Player.UserId)
	if getData then
		print("Test")
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local Key
	Key = Player.UserId
	local newTable = {}
	local findData = RS:FindFirstChild(Player.Name.."-Inventory.UID-"..Player.UserId)
	if findData then
		for i,v in pairs(findData:GetChildren()) do
		    local findNames = v.Name
		    table.insert(newTable,findNames)
		    DSS:SetAsync(Key,newTable)
	    end
	end
end)

Thank you if you help!

1 answer

Hey, how are you doing?

My guess would be that it'd be a timeout, or something of the likes.

    if findData then
        for i,v in pairs(findData:GetChildren()) do
            local findNames = v.Name
            table.insert(newTable,findNames)
            DSS:SetAsync(Key,newTable) ---
        end
    end

The line that I marked worries me since that it technically keeps saving every single time a new object was saved into the table.

Place that SetAsync outside of the for loop and see what happens.

    if findData then
        for i,v in pairs(findData:GetChildren()) do
            local findNames = v.Name
            table.insert(newTable,findNames)
        end
	 DSS:SetAsync(Key,newTable)
    end

1 comment

0

Sorry, but nothing UH OH ;( I'm not gettiing an error

This discussion is preserved as it was. New answers, comments, and votes are closed.