Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

if/then statement not working due to incomplete statement error?

Asked by 4 years ago

I'm making a function that can be called from the main module to the GUIHandler when the player clicks the purchase button in the GUI. This function is supposed to (when the player clicks the button) confirm that the player has enough currency to purchase the item, then decreases the amount of the player's currency by whatever the item price is. For some reason I am getting an error stating that I need a function call after "then"

local function Purchase()
    if Plr.DataLog.Cubits.Value >= 10 then
        Plr.DataLog.Cubits.Value - 10  --This line is where the error is occurring.
    else
        print("Insufficient Funds")
end

I am really stumped at this. Any advice will be great, thanks!

0
Can you show me the exact error that is in the console? alivemaeonman 14 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Simple fix, not really sure how to explain this but, here's the answer:

local function Purchase()
    if Plr.DataLog.Cubits.Value >= 10 then
        Plr.DataLog.Cubits.Value = Plr.DataLog.Cubits.Value - 10  --This line is where the error is occurring.
    else
        print("Insufficient Funds")
end

If anyone has a way to explain to this, post a comment under this answer.

0
lol you were kinda stupid tawk u tried to subtract the cubits value straight but u have to always put a equal sign and do the subtracting after the equal xd or else make no sense TNTIsLyfe 152 — 4y
0
When they buy the item, it would subtract the currency though. 6zk8 95 — 4y
0
TNTIsLyfe+ I see what you mean, haha this'll be the last time I work on code at 1am in the morning. Looking at it now it makes tons more sense. tawk1215 47 — 4y
Ad
Log in to vote
0
Answered by
6zk8 95
4 years ago
Edited 4 years ago

You need an end for the if statement:

local function Purchase()
    if Plr.DataLog.Cubits.Value >= 10 then
        Plr.DataLog.Cubits.Value - 10  --This line is where the error is occurring.
    else
        print("Insufficient Funds")
   end <--- Another end
end

You have an end for the function but not for the if loop, which might be why it is not working/you have an error.

0
That's not the reason but thanks for catching that! tawk1215 47 — 4y

Answer this question