Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

1 comment

0

Can you show me the exact error that is in the console?

2 answers

✓ Accepted answer

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.

3 comments

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

0

When they buy the item, it would subtract the currency though.

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.

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.

1 comment

0

That's not the reason but thanks for catching that!

This discussion is preserved as it was. New answers, comments, and votes are closed.