Why Wont I Level Up

Hello, so im making a game that has a level up system in it. Most of the times when i join the game my exp and leveling is fine. But Sometimes this happends.

Gyazo Link

https://gyazo.com/8a684d9d12c18f3fb77f8645e5f8e0a0

Code

game.Players.PlayerAdded:Connect(function(player)
print(“Leveling6”)
wait(.1)
local Exp = player.Stats.Exp
local Level = player.Stats.Level
local Points = player.Stats.Points
local ExpNeed = player.Stats.ExpNeed
print(“Leveling87”)

	while wait(.4) do
		print("Leveling1")
		if Exp.Value >= ExpNeed.Value and Level.Value <= 1999 then --and Level.Value <= 1999
			print("Leveling2")
			Level.Value = Level.Value + 1
			print("Leveling3")
			Points.Value = Points.Value + 3
			print("Leveling4")
			Exp.Value = Exp.Value - ExpNeed.Value
			print("Leveling5")
			ExpNeed.Value = ExpNeed.Value + 100
			print("Leveling")
		end
	end
end)	

end)

When i try to level up my levels dont increase. I put in print commands to show you where it suddenly stops even tho my exp is greater than my max exp. All values are also changed in server script so i dont think its a local script problem

2 Likes

Does this work other times? The levelling up and the exp? It could be your while loop is prematurely running before your player has time to spawn. Maybe consider changing to a “.changedEvent” or “GetProperyChangedSignal”, so that exp calls the function only when needed to. Not sure though because your problem is too vague. I also don’t know if you’re running this from the client to the sever, etc. There’s also no need to use that much prints, as it may confuse you and you won’t understand where the problem is at. Edit: I learnt about the excessive printing the hard way through one of my posts :sweat_smile:

1 Like

Thanks i checked to see if the exp changed. Although im still having the same problem as last time. My level is not increasing

Nvm it all works thank you for helping me!

1 Like