01 | -- Inside LocalScript -- |
02 | shop.KnifeFrame.MainFrame.Buttons.Buy 1. MouseButton 1 Click:connect( function (onClick) |
03 | confirmframe.Visible = true |
04 | confirmtext.Text = "Are you sure you want to buy 'Foil Knife' ?" |
05 | confirmyes.MouseButton 1 Click:connect( function (buy) |
06 | local running = true |
07 | if player.Credits.Value > 99 and running = = true then |
08 | player.Credits.Value = player.Credits.Value - 100 |
09 | purchasedprompt.Visible = true |
10 | purchasedtext.Text = "You have brought 'Foil Knife' for 100 Credits" |
11 | confirmframe.Visible = false |
12 | running = false |
13 | elseif player.Credits.Value < 100 and running = = true then |
14 | purchasedprompt.Visible = true |
15 | purchasedtext.Text = "You don't have enough credits to buy" |
16 | confirmframe.Visible = false |
17 | running = false |
18 | end |
19 | end ) |
20 | end ) |
For some reason when the player has 100 credits, it says you dont have enough credits, but it takes 100 away, but if you have 300 credits then it takes 300 away and says you have brought the item, I don't know why there is this glitch. Please anyone help.
- NinjoOnline
Look at it logically:
01 | --[[ |
02 | == Equal to |
03 | ~= Not equal to |
04 |
05 | < Less Than |
06 | > More than |
07 |
08 | <= Less than OR equal to |
09 | >= More than OR equal to |
10 | ]] |
11 |
12 | --So, line 05, you're asking if the Credit Value (let's say it's 100) if More than 99. |
13 |
14 | --You could also say |
15 |
16 | if credits > = 100 then -- etc |
17 | -- Ch-Ching! |
18 | else |
19 | -- Not bought |
20 | end |
Try this, the If Then statement is still running after it removes the cash and gives you the foil knife, you want to avoid that.
01 | shop.KnifeFrame.MainFrame.Buttons.Buy 1. MouseButton 1 Click:connect( function (onClick) |
02 | confirmframe.Visible = true |
03 | confirmtext.Text = "Are you sure you want to buy 'Foil Knife' ?" |
04 | confirmyes.MouseButton 1 Click:connect( function (buy) |
05 | local running = true --Every time this is clicked, then running is set to true |
06 | if player.Credits.Value > 99 and running = = true then --If you don't have enough money, then the script will skip these lines of code and running will still be true. |
07 | player.Credits.Value = player.Credits.Value - 100 |
08 | purchasedprompt.Visible = true |
09 | purchasedtext.Text = "You have brought 'Foil Knife' for 100 Credits" |
10 | confirmframe.Visible = false |
11 | running = false --How can both conditions in the next statement be true if this is false now. |
12 | elseif player.Credits.Value < 100 and running = = true then --If it took your money, then it shouldn't run. If you didn't have enough money, then running should remain true and will give you a warning. |
13 | purchasedprompt.Visible = true |
14 | purchasedtext.Text = "You don't have enough credits to buy" |
15 | confirmframe.Visible = false |
16 | running = false |
17 | end |
18 | end ) |
19 | end ) |