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

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

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

✓ Accepted answer

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!

2 comments

0

Thanks!

0

i didn't know you can do that

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