How to make achievements system like here?



So I want to make a system of achievements like in the picture, that is where you have different tasks, you do them and earn or get something question how to do it? Can I have some kind of guides, not just “use the data store”.

You could (obviously) use a datastore to store each value you are tracking. Afterwards, you can use a PlayerAdded event to load the data using GetAsync and create a folder (preferrably inside the player’s Instance) named “stats” or something similar,where you will insert the loaded values. Inside of each achievement, you will add a LocalScript monitoring the Value you added to the “stats” folder.

DataStore script:

local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("PlayerStats")

--suppose we are storing 2 values: Coins and Diamonds. 

game.Players.PlayerAdded:Connect(function(plr)
	
	plr:SetAttribute("stats_loaded",false) 
	
	local data = DataStore:GetAsync(plr.UserId) -- data will be a table with the 2 values: {Coins,Diamonds}
	
	local folder = Instance.new("Folder") --Create a folder where the stats will be saved
	folder.Parent = plr
	folder.Name = "stats"
	local coins = Instance.new("IntValue",folder)
	coins.Name = "coins"
	local diamonds = Instance.new("IntValue",folder)
	diamonds.Name = "diamonds"
	
	if data then
		--player has saved data
		coins.Value = data[1]
		diamonds.Value = data[2]
	else
		--player has no saved data
		warn("player has no data")
		coins.Value = 0
		diamonds.Value = 0
	end
	
	plr:SetAttribute("stats_loaded",true)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	DataStore:SetAsync(plr.UserId,{plr.stats.coins.Value,plr.stats.diamonds.Value} ) -- save the player's data
end)

image

I’ll create 2 basic quests.

image

image

The tracking script inside the quests:

local plr = game.Players.LocalPlayer
local label = script.Parent:WaitForChild("ProgressLabel")

local is_completed = false
repeat wait() until plr:GetAttribute("stats_loaded")

local coins = plr.stats.coins

function ChangeLabel(coins)
	if coins < 100 then
		label.Text = tostring(coins).."/100"
	else
		label.Text = "Complete"
		is_completed = true
	end
end

ChangeLabel(coins.Value)

coins.Changed:Connect(function() -- the value of the coins changed
	if not is_completed then
		ChangeLabel(coins.Value)
	end
end)

The same goes for the diamonds quest.

Result:

Once the player rejoins, the stats of his previous session will be loaded and the quests will stay the same as when he left.

Note: When awarding the player, make sure to check if the values on the client are the same as the values in the server,since exploiters can easily manipulate the value of the stats locally.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.