I am making a story game that has chapters inside of them. I do not want the player to have access to all the chapters, then the story would be ruined overall. I have tried inserting chapterbricks, but they all do not affect anything. I need help with making this. I do not know how to lock certain chapters and make unlockedchapters after a chapter was completed. This is getting very difficult for me and I do not know how to make unlocked and locked chapters.
This is pretty simple. Add checks when a player clicks on a chapter. If X, Y and Z conditions are met they can go in. If X, Y and Z conditions are not met, then its locked.
If statements 101.
If you want to lock it, save what chapter a user did and only unlock the one after it (makes sense, because if they just did chapter 7, theyād then want to move to chapter 8). Upon completion of chapter 8, bump the saved number up.
What is a āchapterā in this case? Is it a physical area of your game? Some scripted events that happen? Some pages from a book youāve scanned and put on a GUI kindle?
No, In my game there is chapters. I donāt want the player to have access to every single one, I just want to make locked chapters when the player didnāt complete the one before it.
If you know how to use DataStore you could add values for the player that say if a certain chapter has been completed or not, for example:
if Chapter2_Completed == true then -- If the player completed chapter 2
PlayChapter(3) -- Play chapter 3
end
This code will never work if you insert it in the game because you have to set these variables by yourself, if you are using a teleportation system and want to prevent the player from entering other chapters simply kick the player once he enters the chapter place if he hasnāt completed the previous chapter
If you are asking how to display a chapter as locked and a chapter as unlocked, you could make a local script that asks the server if a certain chapter is unlocked or not through a RemoteFunction, more details here: Custom Events and Callbacks | Documentation - Roblox Creator Hub
I think you should add an ObjectValue to each chapter, each one having āFalseā as the value. When the player completes a chapter, itās value is set to āTrueā. Then when they want to move on, the selected chapter checks if the last one has āTrueā in itās value. If the previous chapterās ObjectValue is āTrueā, then it will let that player play the chapter. Does this make sense?
It does not make much sense. I do not know how to work true and false values. It is hard understanding each value for me, because I havenāt worked with values very much and I am new with them.
You should use BoolValue not ObjectValue
Yeah⦠I donāt have much experience with values so thanks for the correction.
The short answer is āit depends on what your game isā.
However, thereās some common things that maybe can help push you in the right direction:
Loading chapters on the client
- Have a RemoteFunction in ReplicatedStorage where clients can request chapters from the server.
- Store the chapters (be them models, GUIs, whatever) in ServerScriptService
- When the RemoteFunction is invoked by a client, have the server check if that client is allowed to obtain that chapter
- If they are (see next section), it can send the chapter to the client so the client can render it.
Checking if a player can access a chapter
As @rokoblox5 said, use datastores. Keep track of what chapters a player has unlocked, and return true from your remote event only if theyāve unlocked the right ones. Without more info from you, thereās not much more to say here.
Keeping track of which chapters a player has completed
This is totally dependent on what your game is, and how you define ācompleteā and āchapterā.
Basically though, keep some RemoteEvents in ReplicatedStorage, and call them from the client whenever youāve reached a checkpoint (i.e. completed a chapter). A ācheckpointā in your case might be:
- Touching a part
- Talking to a specific NPC
- Killing a specific NPC
- etc.
Depends on your game, again.
The server will be listening to those RemoveEvents, and when a client fires one, it will
- Do some sanity checks to make sure the client isnāt lying (did they kill that NPC they say they just talked to? Are they skipping too many checkpoints)?
- If the server believes the client is telling the truth, update the data store mentioned in the previous section.
@nicemike40 im still struggling with datastores. I do not know how to make the chapter datastores and save them. I tried writing the following script but it didnāt work:
local DataStoreService = game:getservice(āDataStoreServiceā)
local chapters:GetDataStore()
DataStoreService = chapters
local chapters = game:GetService(āDataStoreServiceā)
end
That script doesnāt make sense, and doesnāt actually do anything.
Read this page and this page, they will explain data stores to you better than I could.
Or if you need to learn how to script in general, I recommend you start with the wiki. There are good tutorials on there.
These are like the locked chapters in @Ethanthegrand14ās Before 3AM and @terriblebloxās It Lurks. I have tried using events and they didnāt do any effects to the things. This is getting tricky for me because I do not want the player to spend 60 minutes beating the game and when they leave on accident or just leave they have to beat it again.
What does āthey didnāt do any effects to the thingsā mean? RemoteEvents are just ways to pass messages to/from the server. Theyāre not magic.
Datastore is your friend my man.
You can run a check to see if a player has a specific value saved, and if they do, then unlock the level/chapter.
Example
local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("GeneralSaveData", "Players")
function generateDataKey(player)
local ret = "uid_" .. player.userId
return ret
end
function generateDataTable(player)
local dataTable = {
Points = player.leaderstats.Points.Value,
Wins = player.leaderstats.Wins.Value
}
return dataTable
end
function saveDataForPlayer(player)
local key = generateDataKey(player)
local data = generateDataTable(player)
datastore:SetAsync(key, data)
end
function inputDataToPlayer(player, data)
player.leaderstats.Points.Value = data.Points
player.leaderstats.Wins.Value = data.Wins
end
function loadDataForPlayer(player)
local key = generateDataKey(player)
local data = datastore:GetAsync(key)
inputDataToPlayer(player, data)
end
game.Players.PlayerAdded:connect(function(player)
loadDataForPlayer(player) --Load first thing when they join
player.leaderstats.Wins.Changed:connect(function()
saveDataForPlayer(player) --Save the data when Wins changes value
end)
end)
game.Players.PlayerRemoving:connect(saveDataForPlayer) --Save data when the player leaves the game
Though my game āBefore 3 AMā used badges to save chapters/parts, which i donāt recommend.
Datastore has much more variety to them
Yeah but⦠what is technically the chapter value? Like what type of value would the thing be? I mean I am misunderstanding the value part of stuff, and what type they are supposed to be to unlock and lock certain chapters.
Really it can be what ever you wish. I suggest using numbers, like
if player.leaderstats.Chapters.Value >= 1 then -- ('>=' Equal or greater than), ('==' Equal to), ('<=' Equal or less than)
print("Level 1 unlocked!") -- This should appear in the output if true
end
Ok, so I am assuming that I should put a RemoteEvent in ReplicatedStorage called āChapterUnlockā and put some values for the player to unlock the chapters. I am thinking that the values should be named āChapterUnlockedā and the value number should be the chapter amount unlocked. If my calculations were correct, then maybe it would be successful. I am not sure how a value would trigger when touching a part The part is the value of the chapter unlocked.. There should be a script inside the brick called āUnlockChapterValueā but the code would be tricky to do. I have no clue on what value unlocking by touching a part would affect a chapter but how could the value affect from another game (The normal game) by using a certain service. Im confused which service it would be used for by unlocking values.
Where would the chapter value be? Like after the chapter was completed then what do I do? Would the value be unlocked to the main game and then the datastoreservice for the chapters would be there? I have no clue what this is and how to make locked and unlocked chapters. How would the values be unlocked through game teleportation and then the game inside of it the values would be unlocked through chapters? I think that the game teleportation would affect the main game where you select each chapter and teleport to that game. The datastoreservice makes no sense to me and I do not know the chapter values and how to make them through a leaderboard. This is super hard and struggling to me and I do not know the chapter value for each one that is locked and unlocked. I want to give up already because I literally cannot make unlocked and locked chapters for each one. I suck so much at datastores and this is starting to look like a complete failure for me and I have no clue each one and how to use values.