**Im not very good at scripting so I don't know what is wrong with this script. **
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local LVL = Instance.new("IntValue") LVL.Name = "Level" LVL.Value = 1 LVL.Parent = leaderstats local EXP = Instance.new("IntValue") EXP.Name = "EXP" EXP.Value = 0 EXP.Parent = leaderstats end) EXP.Changed(connect(function(Value) if EXP.Value == Level.Value * 50 then Level.Value = Level.Value + 1 EXP.Value = 0 end)
For example you need 50 XP To level up to level 2, 100 XP to level up to 3, 150 XP to level up to 4 and so on.
Also, how do i make it so if the player has 51 XP, the level will still go up, I had trouble doing it.
Thanks for the help.
PhotonLightning
Hey PhotonLightning,
LVL
and EXP are not in the scope for your function below. Anyways, the answer above gives you the correct code to use but, all you have to do is just move the end) of the PlayerAdded function to the very end and also, in your script you were using the variable Level
which you never declared. It was declared as LVL
. Rather then doing :connect
, do :Connect
because, :connect
is deprecated. This explains what a scope is in RBX.Lua.~~ KingLoneCat
So, um.. My script should be like this?
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local LVL = Instance.new("IntValue") LVL.Name = "Level" LVL.Value = 1 LVL.Parent = leaderstats local EXP = Instance.new("IntValue") EXP.Name = "EXP" EXP.Value = 0 EXP.Parent = leaderstats EXP.Changed(Connect(function(Value) if EXP.Value >= Level.Value * 50 then LVL.Value = Level.Value + 1 EXP.Value = 0 end end)
If you want the level to change when even when it's not fifty you can't use == you have to use EXP.Value >= LVL.Value * 50
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local LVL = Instance.new("IntValue") LVL.Name = "Level" LVL.Value = 1 LVL.Parent = leaderstats local EXP = Instance.new("IntValue") EXP.Name = "EXP" EXP.Value = 0 EXP.Parent = leaderstats end) EXP.Changed:connect(function() if EXP.Value >= LVL.Value * 50 then LVL.Value = LVL.Value + 1 EXP.Value = 0 end end)
I noticed you made a few beginner errors like forgetting ends and syntax errors but that is ok since you said you are new. Try integrating the script I just showed you; if it still doesn't work try it in player and remember to use the output so you can tell us what error you are recieving.
Hope this helped