It won't remove my money

I’m trying to make a system when you buy a badge with Money it will give you the badge. The issue i’m having is when I buy the badge it won’t remove my money and give me the badge still.

What did I do wrong? if you can show me what to change that would really help. I am still learning scripting.

Did I not read the code good or do I not see anything removing something

1 Like

Please use indentation if you want other people to help you with the script

1 Like
p.leaderstats[Money].Value = p.leaderstats[Money].Value - 1

or use some other operator, but I don’t really understand the thing you want to do, because you are asking for help about subtracting money , but I don’t understand what is working and what isn’t

It will give me the badge, but not subtract the money is my problem

Well, I don’t see that you are trying to take away any money in your script just put your money variable and - the desired amount?

By Using @grandisy solution here is the script:

function Badge()
local p = script.Parent.Parent.Parent.Parent
local a ="Message")
local BadgeID = 2128249861
local StatToChange = "Money"
local HowMuch = 100
function oc()
repeat wait() until p:FindFirstChild("leaderstats")

if p.leaderstats[StatToChange].Changed:Connect(function()
if p.leaderstats[StatToChange].Value < HowMuch + 1 then -- idk why you even need the addition
a.Parent = p
-- First Of all your text is all over the place, here is a better one:
a.Text = "Not Enough Money, You need to get "..HowMuch.." "..StatToChange..", You need to get "..HowMuch-p.leaderstats[StatToChange].Value.." more "..StatToChange.."." -- it will print, and lets say you have 10 cash: "Not Enough Money, You need to get 100 Money, You need to get 90 more Money.
wait(5) -- wait(2 or 3 would be better, but its your choice)
a:Destroy() -- Destroy() is better than remove()
game:GetService("BadgeService"):AwardBadge(p.UserId, BadgeID)
p.leaderstats[StatToChange].Value = p.leaderstats[StatToChange].Value - HowMuch


This has taken forever to do if you send out a text it would be easier, but you sented a image


Why do you write a script for him? He should do the code, stop trying to get solutions

Thank you it WORKS!! Sorry about the image still learning the Devforum I didn’t think to paste my code in devforum.

1 Like

because he didnt understand anything about @grandisy Solution