I need help with quest saving

ive started learning about data store like week ago and i want to create quest saving
like:list of current quests you got with saved info like name of mission current level progress
like i know how to save 1 quest but not more then 1
so when player leaves it saves and player joins it keeps it info, any help?

You can put the missions in a table and save.

Adding on to what @SacerRaym_BR said. If you know about tables, then you can put it into a table and save it like that, here’s an example.

local DSS = game:GetService("DataStoreService")
local QuestSaveServer = DSS:GetDataStore("QuestSave")
Quests = {
   ["Quest1"] = true,
   ["Quest2"] = false,
   ["Quest3"] = false,
   ["Quest4"] = false,
}

QuestSaveServer:SetAsync(plr.UserId, Quests)

You’ll need to slightly modify this to make it player specific.

1 Like

To save this type of data you’ll need the use of a dictionary for this. Such as in a way that it is like this:

local queststable = {
    ["Quest1"] = {},
    ["Quest2"] = {}
}
DataStore:UpdateAsync(..., function() return queststable end)

And so on like this!

you mean i should use table.insert to put the info into quest? and if i like get another quest like third i should insert it too?
and how to do so it removes data if quest is finished
i still dont understand a bit

like

table.insert(queststable,quest)
table.insert(questsable[quest],quest.Info:GetChildren())

There’s really some way to insert elements into a collection, these are some:

local t = {} -- we create a new collection/object/table however

--[[
   This will basically insert a new element into the collection within the last
   position, using the length operator (which gets the length of our table)
   and then we insert it adding one index to it (meaning that if it's 2, it will be
   inserted on the 3rd index).
]]
t[#t + 1] = ...

--[[
   This will get us a key/value (being on the hash part) that can be accessed within 
   the key, such as if t[key].
]]
t["foo"] = ...

--[[
   The same as the one above, just in a different way.
]]
t.fooexample = ...

--[[
    It is better to use the first one tho since it doesn't require a function to invoke.
    from a library.
]]
table.insert(t, ...)

Anyway, all of these could work for you.

1 Like

ok ill try it maybe it should work since you typed with alot of info lol

2 Likes

do i use like

local info = {}
local quests = {}
for i,questinfo in pairs(quest.Info:GetChildren()) do
      if questinfo:IsA("StringValue") or questinfo:IsA("NumberValue") then
            table.insert(info,questinfo)
      end
end
quests[#quests + 1] = info

right?

OP, meet ProfileService!

If you’re learning about DataStore, I heavily recommend you give this module a try, assuming that you’re trying to save individual players’ “have I done a quest or not?” related data. You can assign it via a table and have a player’s “Profile” save each time a change is made or when they leave.

It can seem a bit daunting at first, but it’s a godsend to your game’s DataStore workflow and efficiency.

We can’t really use these forums to give out individual scripts or guidance, but the documentation on there is easy to understand once you start demonstrating it yourself.
Have fun and good luck!

You’re inserting Instances which aren’t valid to be saved in the DataStore, you’ll need to save the .Value of it! Such as if it was "Hello, world!", then you’ll need to save that.

but then how it detect which value is?

What do you mean with this tho?

no like the coin reward or exp reward or level requirement and name

Contact me on discord, it is better to actually get this to there since we’re just flooding the topic and not letting other topics being shown in the list.

Discord: sharkyboy#2024

Just place a Value in the Player when they join and the Value of the Value is the Value you saved like this:

local DSS = game:GetService("DataStoreService")

loca QuestData = DSS:GetDataStore("QuestData")

game.Players.PlayerAdded:Connect(function(plr)

local Value1 = instance.new("BoolValue") 

Value1.Value = QuestData:GetAsync(plr.UserId.."-SomeRandomQuestName")
if Value1.Value == nil then
Value1.Value = false
end

Value1.Changed:Connect(function(NewValue)
NewValue:SetAsync(plr.UserId.."-SomeRandomQuestName")
end)
end)

if you want more quests just add more Values and do the same with them as you did with the first one Only give them a different Key.

ive already solved the problem so yeah thank you and sorry for wasting you’r time