Is there a way to make locked "Chapters"?

I’m making a horror game and it may be pretty long, so I tried to use “Chapters” as a way of making it easy to access if a player wants to replay a certain part, but there is a few issues.

What I want for this, is having a way to make “Locked and Unlocked” Chapters within a game using gui’s and also leaderstats using a Datastore.

Or for quick reference, the chapter selection in @terribleblox’s game, “It Lurks” When you Play you can chose chapters, and you can only play certain chapters once you reached a certain point in the game, and if you didn’t you can’t

That is what I am aiming for.

I already have a main menu with three chapters (Tests) and also a Datasave and Datastore function

MainMenu script: (Not really useful but whatever)

Chapter1:TweenPosition(
	UDim2.new(0.144, 0,0.437, 0), -- ORIGINAL - 0.144, 0,1.08, 0
	Enum.EasingDirection.InOut,
	Enum.EasingStyle.Quad,
	0.75)
wait(0.025)
Chapter2:TweenPosition(
	UDim2.new(0.394, 0,0.437, 0), -- ORIGINAL - 0.394, 0,1.08, 0
	Enum.EasingDirection.InOut,
	Enum.EasingStyle.Quad,
	0.75)
wait(0.025)
Chapter3:TweenPosition(
	UDim2.new(0.648, 0,0.437, 0), -- ORIGINAL - 0.648, 0,1.08, 0
	Enum.EasingDirection.InOut,
	Enum.EasingStyle.Quad,
	0.75)

wait(1)

BackButton:TweenPosition(
	UDim2.new(0.024, 0,0.872, 0 ), -- ORIGINAL - -0.13, 0,0.872, 0
	Enum.EasingDirection.InOut,
	Enum.EasingStyle.Quad,
	0.65
)
BackButton.MouseButton1Click:Connect(function()
	BackButton:TweenPosition(
		UDim2.new(-0.13, 0,0.872, 0), -- ORIGINAL - 0.024, 0,0.872, 0
		Enum.EasingDirection.InOut,
		Enum.EasingStyle.Quad,
		0.65)
	
	wait(1)
	
	
	Chapter1:TweenPosition(
		UDim2.new(0.144, 0,1.08, 0), -- ORIGINAL - 0.144, 0,1.08, 0
		Enum.EasingDirection.InOut,
		Enum.EasingStyle.Quad,
		0.75)
	wait(0.025)
	Chapter2:TweenPosition(
		UDim2.new(0.394, 0,1.08, 0), -- ORIGINAL - 0.394, 0,1.08, 0
		Enum.EasingDirection.InOut,
		Enum.EasingStyle.Quad,
		0.75)
	wait(0.025)
	Chapter3:TweenPosition(
		UDim2.new(0.648, 0,1.08, 0), -- ORIGINAL - 0.648, 0,1.08, 0
		Enum.EasingDirection.InOut,
		Enum.EasingStyle.Quad,
		0.75)

DataStore Script:

`local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player

local Chapter = Instance.new("IntValue")
Chapter.Name = "Chapter"
Chapter.Parent = leaderstats

local data

local success, errormessage = pcall(function()
	data = myDataStore:GetAsync(player.UserId.."-Chapter")
end)

if success then
	Chapter.Value = data
else
	print("Data Not Saved")
	warn(errormessage)
end

end)

game.Players.PlayerRemoving:Connect(function(player)

local success, errormessage = pcall(function()	
	myDataStore:SetAsync(player.UserId.."-Chapter",player.leaderstats.Chapter.Value)
end)

if success then
	print("Data Saved")
else
	print("Data Not Saved")
	warn(errormessage)
end

end)
`

I tried everything I could, using extra frames, detecting the players leaderstats Values, and trying to use that, using other posts of guis and nothing has worked, so any help is apreciated : )

PS: If you are sending in code, can you try to roughly explain it please? Thanks

(Sorry if there are spelling errors, I was in a rush)

If you want to achieve a “locked chapter” system you should first try detecting whether a player has finished a chapter, after that you can save the player’s data. Data can be shared between a game/place.

Before you ponder into that though, does the script you provide have any errors?

Sorry for the very delayed reply

Im trying to achieve this using the leaderstats with a value named “Chapter”, and I would use the amount of it to unlock parts. I also have a datastore for it (Listed above) Saving that value.

Screenshot 2022-09-20 153735

Only problem is that i don’t have a for sure way to make these chapters “Unlocked” and actually able to work.

Also, if this way of making the chapters unlocked is innefficient, are you able to tell me another way?

Cheers