Leveling system not working (solved)

So, for some reason when a player hits level 100 their level doesn’t reset and they don’t gain a Prestige level, why isn’t this working?

It is highly recommended that you do not use the Second Argument with Instance.new() due to performance reasons, plus you arent saving the Values.

But by looking at it, it should work.

For some reason it doesn’t idk why

After the exp.Changed function, add an End, to end that function, you have 2 functions inside each other (like @Free_Br1cks script)

1 Like

I don’t know why the formatting is all over the place, but try this:

exp.Changed:Connect(function(Changed)
	if exp.Value >= RequiredExp.Value then
		exp.Value = 0
		level.Value += 1
	end
end)

level.Changed:Connect(function(Changed)
	if level.Value >= RequiredLevels.Value then
		level.Value = 1
		
		Prestige.Value += 1
		RequiredExp.Value += 1000
	end
end)
3 Likes

Omg thanks! I really need to pay attention to format more!

1 Like

Some additional explanation:

When you create Multiple Events for one object, it does not remove one of them, instead what you will have is more than one Event listening for a Change, or an Action.

When the Change Occurs, Normally It would fire once because one Event is listening for the Change, but if you have multiple, It will cause it to fire Multiple Times, due to Multiple listen for the change, this can cause Perfpormance issues, because you are giving the Server (or Client) a lot of information to process, causing it to lag.

This happens when there is potentially hundreds of the same Event being listened to on the same object.

With the case of exp, everytime Changed is fired by a Change occurring within the Values, you are creating an Event each time that happens, which is not a good thing.

Also, your script has a lot of making Values, so it may be good to use a function to make them, especially if your are going to make more values, like this:


local function MakeInstance(Type, Name, Parent, StartValue)
	local ThingMade
	if Type == "folder" then
		ThingMade = Instance.new("Folder")
	elseif Type == "Number" then
		ThingMade = Instance.new("NumberValue")
	elseif Type == "string" then
		ThingMade = Instance.new("StringValue")
	else  
		return
	end
	ThingMade.Name = Name
	ThingMade.Parent = Parent
	if StartValue ~= nil then
		ThingMade.Value = StartValue
	end
end


game.Players.PlayerAdded:Connect(function(Player)
	MakeInstance("folder", "leaderstats", Player)
	MakeInstance("Number", "exp", Player:FindFirstChild("leaderstats"))
	MakeInstance("Number", "level",  Player:FindFirstChild("leaderstats"), 1)
	MakeInstance("Number", "Prestige",  Player:FindFirstChild("leaderstats"))
	MakeInstance("Number", "RequiredLevels", Player, 100)
	MakeInstance("Number", "RequiredExp", Player, 1000)
	
end)

I like to work with these function when working with a lot of values, so I don’t have to write each value down. But that is just a recommendation

That’s probably way more efficient. I like this way a bit better since it’s easy to find a specific stat since it’s all written out. But in the future I’ll try using this!

1 Like

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