Problem with leaderstats value/script

Hey there,

I am currently working on a game and I was setting up the shop, but in my code while the script seems to be correct the output I am getting is incorrect.

If I am doing something wrong please correct me.

I’m confused what is the problem exactly, is it what’s printing? is the script not working?

can you show the complete error? and show the line 19

Line 19 is empty. And its about some other events that the script is handling.

If you look at the script I print the amount of money that the player has. Which is shown as 500 in the output as well. But in the if statement the script does not go through with the <= 299 criteria and directly shows that the player does not have the money.

image

It’s printing “Player doesn’t have enough money” because that’s what you put there

inside the if then thingy, you checked if the player doesn’t have enough money, so when you said “else”, you we’re checking if the player has enough money, It’s nothing with your script, it’s just that the game is getting that you DO have enough money, and when it sees the “else” it prints “Player doesn’t have enough money”.

–Swift

So if I do not write the else statement. It should only see if the player has more then 299 money and if the player does not it does nothing?

If the player doesn’t have enough money, it prints “you’re fired”,

the else statement is just checking if the player does have enough money, just change the print inside the else.

From what I understand from this code is that, If the player’s PcValue is 2 then it will print “Player already has the same” and if it does not it will fire the event. And thats the main confusion I have with the script where it should check for 299.

Yes, basically that’s what it does.

Now when I ask the script to see if the money value is less then 299, it does print “You’re fired” while in the output you can see the money value is 500.

That’s why you need the else statement, because it’s checking if the player has a higher value than 299, if it DOES then the else statement will print whatever is inside it.

–Example–

if player.leaderstats.Money.Value == 500 then -- or whatever you want the value to be

print("yes")

else

print("no")
end

In the example it’s checking if the money value is 500, if it is it prints “yes”, if it’s not (else statement) it print’s “no”.

Do you understand?

Its the same thing in the original photo I posted but instead of the exact number of 500 Im seeing if the number is equal to or above 299 (<= 299). But it is just not working.

in your original script, you we’re check if it’s 299 or not in the end your actual value is 500, when you don’t add a else statement it doesn’t have anything else to print BUT “you’re fired”, when you add an else statement(I don’t know why you removed it, I said the change the print statement inside it.), it checks if your value is higher than 299, if it IS
and, then it does what’s inside the else statement,

here is a youtube tutorial on them, cause I don’t know if you understand what I’m trying to say as I’m bad at explaining.

Ok let me explain fresh

My code is:

local StoreHub = game.ReplicatedStorage.StoreEvents

StoreHub.PCStore.One.OnServerEvent:Connect(function(player)
print(player.Name)
print(player.leaderstats.Money.Value)
if player.leaderstats.Money.Value <= 299 then
player.PlayerData.PcValue.Value = 2
print(“You’re fired”)
end
end)

So here the output for the money value is 500.

And the script is asking if the value of the money is equal to or above 299. Which we knows it is as its 500. So it should print “You’re fired”. And if the value is below 299 it shouldn’t do anything.

It is the same as in the video you sent where,
The hotdog value is 3

And the script is:

local Hotdogs = 3
if Hotdogs == 3 then
print(“Hotdogs is equal to three”)
else
print(“Hotdogs is not equal to three”)
end

So if here we would have asked instead of the Hotdogs value being exactly 3 (== 3) it to be above of equal to 3 (<= 3) then it should have printed “Hotdogs is equal to three” and if the Hotdogs are below 3 then “Hotdogs are not equal to three”.

1 Like

Could someone help me with this problem?

You’re using the wrong operator. You need to use the >= operator.

I am checking if the value (500) is higher then 299. That’s why I’m using <=

Yeah, if you want to check if the value is higher than 299, then you’d have to use >=.

There is nothing wrong with the scripts, you are just using the wrong operators which is making you confused.

As you can see in your original picture, 500 is your money and 500 is less than or equal to 299 is equal to false and that is why it will output the else statement which is “Player doesn’t have enough money”. Just change what you’re printing in the else statement to “You have enough money” and you should be good.