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

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

-- 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

1 comment

0

Make the credits object a variable

2 answers

✓ Accepted answer

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

1 comment

0

i tried the >= but that made it worst, plus didnt answer my question very well.

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)

3 comments

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?

0

Well, I'm not quite too sure what the problem is. Not unless you have the MouseButton connection in a loop...

0

its not in loop, that is all the code in the localscript

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