Script not detecting if value is greater than another

if Level.Value < BaseStats.MaxLevel then
			print("ItsLower")
			if Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value then
				Level.Value = Level.Value + 1
				print("ok")
				Experience.Value = Experience.Value - ExperienceNeed.Value
			end
		end

Hello, so i have this script, it works and prints “ItsLower” because the value is smaller. But for some reason the Exp if statement doesn’t work even though i literally look and Exp was greater than ExpNeed. And theres no output or anything, and i have 0 idea why it wont work

1 Like

Some code optimizations:

if Level.Value < BaseStats.MaxLevel then
			print("ItsLower")
			if Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value then
				Level.Value += 1
				print("ok")
				Experience.Value -= ExperienceNeed.Value
			end
		end

If you want to debug it, do
print(Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value)
like this:

if Level.Value < BaseStats.MaxLevel then
			print(Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value)
			if Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value then
				Level.Value += 1
				print("ok")
				Experience.Value -= ExperienceNeed.Value
			end
		end

For some reason it stays false

Anchored is false because BodyPosition only works for Unanchored Objects

Wait what, i dont understand how we began talking about Anchored and BodyPosition

Wrong Post, Ignore that.
anyway you need to fix your values

Oh okay lol, what do you mean fix my values?

One or both of the values you provided is incorrect. meaning it is always false
Edit: Great, Now I’m forced to keep that mistake there for FOURTEEN HOURS

But i can litterally see the values, and one is higher than the other

Something in the script is going wrong

Well its clearly that if statement because it still prints before that

You said the print returns “false” meaning that, one of your values is skewed. and because it returns false, it never runs the code in the if statement.

Have you tried to set your Experience value to be smaller and not bigger for testing? because that could be the issue.

Yes, if i start it off by checking if its less than(which by default it is) it prints, but for some reason when i change it doesnt update or smth with the script(btw this is in a serverscript if that changes anything)

if your Experience value changes rerun the script

How will i do that? Like rerun the script

Also, this is used in a playeradded function, so im not sure if thats a good idea

The player can only level up when a player is added???

Nope, thats not how ti works at all, its constantly checking since the player has been added

function NewLevel()
if Level.Value < BaseStats.MaxLevel then
print(Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value)
if Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value then
Level.Value += 1
print(“ok”)
Experience.Value -= ExperienceNeed.Value
end
end
end
Experience.Changed:Connect(NewLevel)

1 Like