DataStore2:Set(nil) wont save

ok so. i have quest system and on completing it it should remove quest, but it wont save after leaving.

questmodule.QuestRemove = function(plr,QuestName,OnRemoveFunc)
	if QuestName == nil then
		warn("Quest name cant be nil")
		return
	end
	if plr == nil then
		warn("Player cant be nil")
		return
	end
	
	local QuestData = DataStore2("QuestDataNew4", plr)
	
	print("Removed Quest")
	QuestData:Set(nil)
	
        if OnRemoveFunc ~= nil then
		OnRemoveFunc()
	end
end

EDIT: i have BoolValue SaveInStudio

1 Like

I don’t know much about DataStores but maybe try SetAsync()

:Set is a function from Datastore2.

1 Like

When you test it without have picked any quest try to print the actual quest, if will be printed nil there is a problem with the save script

I recommend you using :RemoveAsync(). Datastore can’t save nil values.
Edit : I mean to reply to the post, sorry.

1 Like
local QuestData = DataStore2("QuestDataNew4", plr):Get() -- this gets the data from the datastore
QuestData = nil -- this sets the value to nil (assuming it is not a table)
DataStore2("QuestDataNew4", plr):Set(QuestData) -- this saves the QuestData data to the player's Datastore

I’m not too sure if this would work but please test it out.

Already did, it checks quest and if it exist it removing it. I used :Set(nil) and its settings to nil, like quest doesn’t exist anymore. But then i leaves it wont save it.


Looking at the documentation you should be able to set nil.
If you are unable to then just set it to “nil” or another value which you can compare as nil in your script.

I searched up in DataStore2 forum page about clearing data, creator said i just need do :Set(nil) to clear data, it sets but wont save.

Have you placed DataStore2.Combine(… keys)?

No i guess. Im rly confused how to use it. Would you explain me?

You can read on it here, you have to use it before you attempt to get or set any data.

The exact explanation from @Kampfkarren:

In normal data stores, you’d save all your data into one giant player data table to minimize data loss/throttling. In DataStore2, this is a built in feature! Simply use DataStore2.Combine("DATA", "any", "keys", "here") , or call it multiple times ( DataStore2.Combine("DATA", "coins"); DataStore2.Combine("DATA", "guns") ).

These are called “combined data stores”, they save all your data into one big table but without the cost of ergonomics (you don’t have to get the entire data just to manipulate one part of it).

Can i get usage example? Or its like DataStore2.Combine(“PlayersInfo”,“coins”,“points”,“kills”) or its .Combine(“PlayersInfo”, coins,points,kills)

1st one is right :smiley:

You just need to put it at the top of your script before you do any data saving, fetching or removal.

Datastore2.Combine("Key1", "Key2" ... )

In my case what i should combine? Like .Combine(“QuestData4”,“quest”)?

Combine every single key you are going to reference in your script. So in this case, just “QuestDataNew4” if that’s all you’re using.

1 Like

Thanks man, i would test it soon. I will mark it as solution if it works.

1 Like