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.
while wait() do if script.Parent.Value > script.Parent.Parent.xptolevel.Value then print("xp is greater than xptolevel") end 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.
local lighting = game:GetService("Lighting") for _,x in pairs(lighting:GetChildren())do x.Changed:connect(function() if x.Name == "xp" and x.Value >= x.Parent["xptolevel"] then --this may seem sketch but it works fine. print("Player has leveled up!") x.Parent["xptolevel"].Value = x.Parent["xptolevel"].Value + 100 if x.Name == "level" then x.Value = x.Value + 1 end x.Value = 0 end end) 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****