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
01-- Inside LocalScript --
02shop.KnifeFrame.MainFrame.Buttons.Buy1.MouseButton1Click:connect(function(onClick)
03    confirmframe.Visible = true
04    confirmtext.Text = "Are you sure you want to buy 'Foil Knife' ?"
05    confirmyes.MouseButton1Click: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)
20end)

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:

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 
16if credits >= 100 then -- etc
17  -- Ch-Ching!
18else
19 -- Not bought
20end
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.

01shop.KnifeFrame.MainFrame.Buttons.Buy1.MouseButton1Click:connect(function(onClick)
02    confirmframe.Visible = true
03    confirmtext.Text = "Are you sure you want to buy 'Foil Knife' ?"
04    confirmyes.MouseButton1Click: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)
19end)
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