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)
v.Touched:Connect(function(hit)
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
end
end
end
end)
end
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.