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()
print("Test")
end
local p = script.Parent.Parent.Parent.Parent
local a = Instance.new("Message")
local BadgeID = 2128249861
local StatToChange = "Money"
local HowMuch = 100
function oc()
game.Players.PlayerAdded:Connect(function(p)
repeat wait() until p:FindFirstChild("leaderstats")
end)

if p.leaderstats[StatToChange].Changed:Connect(function()
end)
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()
else
game:GetService("BadgeService"):AwardBadge(p.UserId, BadgeID)
p.leaderstats[StatToChange].Value = p.leaderstats[StatToChange].Value - HowMuch
end

end
script.Parent.MouseButton1Down:Connect(oc)

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

2 Likes

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