I wanna make it so when i get the quest from npc it’ll be like this in the gui,
the real problem is i do not know how can i make a quest system with datastore,
like how can i make the quest system like this and make it so it’ll be saved when you rejoin etc.
i’ve tried few stuff by myself but couldn’t really achieve what i wanted,
(doing some stuff about the gui is not problem but the quest with data store stuff confusing me)
local DataTemplate = {
Quests = {
{
Progress = 0,
Limit = 50000,
Reward = 1000,
Focus = "Strength"
}
}
... -- Other stuff like money
}
-- You can just concatenate the rest:
-- "Gain" + Quests[1].Limit + Quests[1].Focus
-- For the comma on Limit(50,000) you could search it on google on how to do that
As for the system, just make a list of quests and use math.random to pick which quest to pick. If you want a much more advanced way, like if the limit and reward are different, just use math.random for the limit and divide it by 50, since 50,000/1000 equals 50. If we got a number of 55,000, the reward would be 1,100.
You’d want to keep all datapoints like progress and “coins” within a table in the database. You’d also probably want to store the players’ userId to identify which datapoints belong to which player. Good luck.
You would of course use an event, let’s say a tool for strength, which contains a local script and a server script, but this depends on the structure of your game. The part that fires the event would be the server script, because to get the reward would be server-side. In the event listener, the progress will increment. After the progress >= limit, then a reward would be given.
You would also make a script dedicated to a QuestService. This would be a lot easier if you’re using a framework such as Knit. The service might look something like this:
local QuestService = {}
local Knit = require(game.ReplicatedStorage.Packages.Knit)
-- This service load and saves the player's data when leaving the game
local Signal = Knit.Util.Signal
local PlayerService = Knit.Services.PlayerService
local ListOfTools = {"Strength"}
function QuestService.KnitInit()
--[[
This function is understandable.
When ever a player joins after data has
been loaded the function that was passed
get's fired and passed in the Player
The Player is not an object rather a metatable,
which contains the PlayerObject from Players,
and their data.
You don't have to bother saving the data from
here everything is being saved on the PlayerService
]]
local function IncrementProgress(toolName, Quests, Player)
for index, quest in ipairs(Quests) do
if not (quest.Focus == toolName) then
continue
end
quest.Progress += 1
if quest.Progress >= quest.Limit then
table.remove(Quests, index)
Player.leaderstats.Money += quest.Reward
--[[
You then have to fire an event to the
the player to add effects or remove
the quest from their list or other stuff
that you want to do with it.
]]
end
end
end
PlayerService:PlayerDataLoaded(function(Player)
--[[
As I have said before Player is a metamethod
which also contains __call that returns the
player object from game.Players.
]]
local Quests = Player:GetData().Qeusts
Quests._Event = Signal.new() -- You might not need this
for _, tools in ipairs(Player().Backpack:GetChildren()) do
if table.find(ListOfTools, tools.Name) then
tools.BindableEvent.Event:Connect(function()
IncrementProgress(tools.Name, Quests, Player())
end)
end
end
end)
end
return QuestService