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

Player's purchase doesn't subtract the player's money in the leaderstat, why?

Asked by 3 years ago
for j, l in pairs(button:GetChildren()) do
        if l.BuyButton.Transparency ~= 1 then
            l.BuyButton.Touched:Connect(function(hit)
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            local money = player.leaderstats.Money.Value
            local cost = l.Cost.Value
                    if money >= cost then
                money = money - cost
                print(money) -- when I print it out, the player's money got subtracted but not in the leaderstats
                        for i, v in pairs(FurnitureTable) do
                            if v.Name == l.Purchase.Value then
                                v.Parent = items
                            end
                        end
                    end
                end)
        end
    end

hello, i made a purchase script where when a player touched a button it will subtract the player's money and the item will be purchased. But, the player's money doesn't get subtracted for a reason.

1 answer

Log in to vote
0
Answered by 3 years ago

Try This,

    if money >= cost then
money -= cost
print(money)

By doing...

money = money - cost

you are setting the variable 'money' to the sum of 'money - cost'

Using

 money -= cost

will subtract the value of the IntValue from leaderstats.

Hope this helps!

0
Thanks! Struggage 10 — 3y
0
i didn't know you can do that Struggage 10 — 3y
Ad

Answer this question