Checking if a value is bigger than 100

So, I’ve got a problem with my code, and I don’t know how to fix it.

	while task.wait(1) do
		if Loadingper.Value <= 100 then

			LoadingTime = LoadingTime + 1


I’m getting this error:

attempt to compare string <= number

If you’re changing the loop, I’d like it to not pause the code if you’re able to do that.

This is my first time using loops other than while true/wait() do😅

Any help is appreciated!! :blush:

LoadingTime is not a Value object

1 Like

This issue is in this line:

Loadingper.Value is a string. You’ll need to type cast it (turn the string into a number).

One of the easiest ways is this, although it isn’t going to work if Loadingper.Value is something like “hello there”:

if tostring(Loadingper.Value) <= 100 then

Now im getting this error:

attempt to compare string <= number

But thank you for replying!!

1 Like

Oh my bad! What was I thinking!?

Here’s the reason why I was wrong and nothing different happened: I turned Loadingper.Value from a string into a string (basically not changing anything).

I meant tonumber() not tostring()

Again, I’m getting an error ;(

attempt to compare nil <= number

I’ve tried

if tonumber(Loadingper.Value) <= 100 and Loadingper.Value ~= nil then

But that didn’t work

Can you provide us with an example of what Loadingper.Value would be please?

Okay, in that case @PoppyandNeivaarecute is right; we would need to know the value of Loadingper to help you.

Whelp, I think I’ve found my problem, Loadingper (Loading%) is MEANT to be a NumberValue but I just went to check and it’s a StringValue (my bad!).

After I changed Loadingper to a NumberValue, my problem was solved. But thank you so so much for your help. :smile: :smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.