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

'>' or '==' not functioning properly?

Asked by 10 years ago
-- 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

0
Make the credits object a variable OniiCh_n 410 — 10y

2 answers

Log in to vote
2
Answered by
hiccup111 231 Moderation Voter
10 years ago

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
0
i tried the >= but that made it worst, plus didnt answer my question very well. NinjoOnline 1146 — 10y
Ad
Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

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)
0
not working... It did nothing , it still takes away 100 credits while saying you dont have enought, same with 200 and 300, only when you buy the 400 does it say you have brought, but it takes away 400 credits instead of 100?? Why is it soo wierd like that? NinjoOnline 1146 — 10y
0
Well, I'm not quite too sure what the problem is. Not unless you have the MouseButton connection in a loop... M39a9am3R 3210 — 10y
0
its not in loop, that is all the code in the localscript NinjoOnline 1146 — 10y

Answer this question