Im trying to create a level select system in which some levels are locked

Basically, I’m making a system where if a player beats a level then in the level select they are granted the ability to move to the next stage. The method I’m trying right now is basically to have a new int value in leaderstats that holds the highest level the player has been to. To do this I created a folder in which I keep the endpoints(that are named by their respective numbers) of the level. Here is my code:

local Players = game:GetService("Players")

local EndPoints = workspace:WaitForChild("EndPoints")  

for i,v in pairs(EndPoints:GetChildren()) do
	local StageNum = tonumber(v.Name)
		local char = hit.Parent
		if char ~= nil then
			local Humanoid = char:FindFirstChildOfClass("Humanoid")
			if Humanoid ~= nil and Humanoid.Health > 0 then
				local player = Players:GetPlayerFromCharacter(char)
				local leaderstats = player.leaderstats
				local highestlev = leaderstats:WaitForChild("Highest Level")
				if highestlev.Value < StageNum then
					highestlev.Value = 	StageNum

So basically once they hit an endpoint the highest level value becomes whatever number the next level is. I just wanted to know if this system is an efficient way to do this, or if it has any flaws, or maybe if I should use a whole other system instead.

1 Like

You may get flagged because I believe this type of post belongs in Code Review. Hope you can find an answer there.


Oh ok thanks I’ll switch it to there

1 Like

Check if it’s a BasePart before you use .Touched, incase you add some scripts or whatever in that folder.

Otherwise I don’t see any bad practices