DataStore2 Help

Thanks for the help i fixed it

1 Like

While I never use DS2 personally, I noticed this 2 wrong implementation when you pass the function for DS2 argument in your code.

local dataquest = QuestDataStore:Get(SetUpData())
-- should be
local dataquest = QuestDataStore:Get(SetUpData) -- notice SetUpData without parentheses 

And this

QuestDataStore:OnUpdate(UpdateQuest())
-- should be
QuestDataStore:OnUpdate(UpdateQuest) -- also without parentheses

See if this fix your problem

Doesnt solve it sadly, but the datastore is getting updated, it’s just the intvalue and stringvalues arent getting updated also

Sorry I’m a little bit confused when you said

because your Datastore data is essentially intvalue (MaxValue and CurrentValue) and stringvalue (QuestName) as well. If Datastore getting updated, then by IntValue and StringValue you referencing the data in the leaderboards display?

yeah, i’m referring to the maxvalue and questname, and i forgot to mention currentvalue that’s my bad. Just need all those 3 update with the datastore.

If that’s the case, I can only see this as the cause

game.Players.PlayerAdded:Connect(function(player)
	-- truncated
	local dataquest = QuestDataStore:Get(SetUpData())
	-- truncated
	local function UpdateQuest()
		QuestName.Value = dataquest["Quest"]["QuestName"]
		MaxValue.Value = dataquest["Quest"]["MaxValue"]
	end
	QuestDataStore:OnUpdate(UpdateQuest())
end)

Like I said I never work with DS2 before so apology if this is wrong conclusion. But by looking at the above code, whenever the DataStore updated it calls UpdateQuest function. And in that function you have the reference of dataquest which is the initial load of your data. In short, your data is running in a loop (keep back to the beginning state)

Maybe somebody with more experiences with DS2 have another solution.

Ah well, i’ll check to see it there are people who know the solution maybe @Kampfkarren might be able to help hopefully. Thanks for your time.

This isn’t a DataStore2 issue.

First, you’re calling the function while sending it to OnUpdate instead of just passing it.

Second, you can’t reuse the same data variable–it doesn’t automatically update. OnUpdate gives you the new data, use that.

I would recommend reading the documentation, which gives a few good examples of OnUpdate.

1 Like

I’ve read the documentation and can’t seem to find anything i’m doing wrong, this is my current script to update the values :

	local function UpdateQuest()
		QuestName.Value = dataquest["Quest"]["QuestName"]
		MaxValue.Value = dataquest["Quest"]["MaxValue"]
	end
	
	QuestDataStore:OnUpdate(UpdateQuest)

Which still doesn’t work. Any ideas on how i can fix my script to make it work?

and this is my ClickDetector script, Note that the saving and loading works completely fine, just that I can’t seem to update the values as the DataStore updates. Here is the ClickDetector Script once again, i’ve updated it a bit.

game.Workspace.Part.ClickDetector.MouseClick:Connect(function(player)
	local pickquest = QuestModule.PickQuest()
	print(pickquest["QuestName"])
	
	local dataquest = DS2("Quest",player)
	local questData = dataquest:Get(SetUpData)
	questData["Quest"]["QuestName"] = pickquest["QuestName"]
	questData["Quest"]["MaxValue"] = pickquest["MaxValue"]
	questData["Quest"]["CurrentValue"] = 0
	
	dataquest:Set(questData)
end)

PS : DS2 is overall amazing, and has made it easier for me to do my inventory system.