Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How comes when I have 50EXP, I don't level up to LVL 2?

Asked by
phxtn 154
7 years ago
Edited 7 years ago

**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

0
I've written what I believe to be the solution you're looking for on a similar question page: https://scriptinghelpers.org/questions/38264/how-would-i-make-this-script-give-1-level-whenever-the-exp-reaches-100#40643 - let me know if you have any questions. ScriptGuider 5640 — 7y
0
Note: You'll have to increase the max experience each time on your own (if you do want max experience to increase each level up). It shouldn't be hard, just use whatever algorithm you think suites it best and throw it back into the function. ScriptGuider 5640 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Hey PhotonLightning,

The answer above fails to mention to you that the variables 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.

Well, I hope I helped and have a great day/night.

~~ KingLoneCat

0
:connect is deprecated? I've always been using it though... I guess it creeped up on me or what because it still works for me :/ iiFlamingIcicle 45 — 7y
0
^ Something can work but, can be deprecated by the roblox wiki. KingLoneCat 2642 — 7y
0
So you're sort of saying I should better change to :Connect so that my game won't be in trouble when :connect stops working I'm confused iiFlamingIcicle 45 — 7y
0
Just don't get in the habit of using deprecated methods, not much needs to be explained. It's like using scotch tape to patch a leak when you could use duct tape. ScriptGuider 5640 — 7y
View all comments (2 more)
0
Thank you, Accepted :) phxtn 154 — 7y
0
Thanks. @PhotonLightning @ScriptGuider KingLoneCat 2642 — 7y
Ad
Log in to vote
1
Answered by
phxtn 154
7 years ago

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)

0
An 'end)' for the second function and also, remove that parenthesis before 'Connect', replace the parenthesis with ':' and also, make sure you use :Connect for the PlayerAdded event rather then using :connect. because ':connect' is deprecated and ':Connect' isn't. KingLoneCat 2642 — 7y
0
Also, in your if statement and also below that, you are using the variable 'Level' again. That should be 'LVL' because 'Level' isn't a variable name in the script. KingLoneCat 2642 — 7y
0
oops, didn't realise, I'm going to make my variables to Level since I'm used to Level instead of LVL. Thanks for the help phxtn 154 — 7y
Log in to vote
0
Answered by 7 years ago

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

0
This code will not work as EXP only exists within the PlayerAdded event so it needs to be moved into the event. User#5423 17 — 7y

Answer this question