-- Inside LocalScript -- shop.KnifeFrame.MainFrame.Buttons.Buy1.MouseButton1Click:connect(function(onClick) confirmframe.Visible = true confirmtext.Text = "Are you sure you want to buy 'Foil Knife' ?" confirmyes.MouseButton1Click:connect(function(buy) local running = true if player.Credits.Value > 99 and running == true then player.Credits.Value = player.Credits.Value - 100 purchasedprompt.Visible = true purchasedtext.Text = "You have brought 'Foil Knife' for 100 Credits" confirmframe.Visible = false running = false elseif player.Credits.Value < 100 and running == true then purchasedprompt.Visible = true purchasedtext.Text = "You don't have enough credits to buy" confirmframe.Visible = false running = false end end) 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:
--[[ == Equal to ~= Not equal to < Less Than > More than <= Less than OR equal to >= More than OR equal to ]] --So, line 05, you're asking if the Credit Value (let's say it's 100) if More than 99. --You could also say if credits >= 100 then -- etc -- Ch-Ching! else -- Not bought 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.
shop.KnifeFrame.MainFrame.Buttons.Buy1.MouseButton1Click:connect(function(onClick) confirmframe.Visible = true confirmtext.Text = "Are you sure you want to buy 'Foil Knife' ?" confirmyes.MouseButton1Click:connect(function(buy) local running = true --Every time this is clicked, then running is set to true 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. player.Credits.Value = player.Credits.Value - 100 purchasedprompt.Visible = true purchasedtext.Text = "You have brought 'Foil Knife' for 100 Credits" confirmframe.Visible = false running = false --How can both conditions in the next statement be true if this is false now. 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. purchasedprompt.Visible = true purchasedtext.Text = "You don't have enough credits to buy" confirmframe.Visible = false running = false end end) end)