Im having some problems to make a level up system, its with GUIs, first I have the script that will change GUI texts to the NumberValue value, it works fine, but I need a script that when the xp is greater than xptolevel its gonna make a action, someone help me!, there's the script: while true do if script.Parent.Value > script.Parent.Parent.xptolevel.Value then print("xp is greater than xptolevel") wait(0.1) end end Here's a screenshot https://imgur.com/a/CgCgN
works perfectly fine for me. Just make sure you don't have the wait inside the if statement, otherwise game will crash if the statement is not true.
1 | while wait() do |
2 | if script.Parent.Value > script.Parent.Parent.xptolevel.Value then |
3 | print ( "xp is greater than xptolevel" ) |
4 | end |
5 | end |
There is a lot more advanced and less destructive ways to do this.
Assuming you have the GUI interface setup, I will just show you a script. A smarter idea would to also be to put this in StarterGui as a normal server script.
01 | local lighting = game:GetService( "Lighting" ) |
02 | for _,x in pairs (lighting:GetChildren()) do |
03 | x.Changed:connect( function () |
04 | if x.Name = = "xp" and x.Value > = x.Parent [ "xptolevel" ] then --this may seem sketch but it works fine. |
05 | print ( "Player has leveled up!" ) |
06 | x.Parent [ "xptolevel" ] .Value = x.Parent [ "xptolevel" ] .Value + 100 |
07 | if x.Name = = "level" then |
08 | x.Value = x.Value + 1 |
09 | end |
10 | x.Value = 0 |
11 | end |
12 | end ) |
13 | end |
Hopefully this works fine for you, and yes there are many other ways to do this but why make the variables? ****YOU CAN PUT THIS SCRIPT ANYWHERE BUT IT MAY BE SAFER TO PUT IN STARTERGUI****