Why do I have negative values in my money?

Hello, could someone tell me how to avoid having negative values ​​in silver? that is to say that sometimes I buy something, even if I don’t have the necessary money, it buys me the object and puts me a negative value, Can you help me please?

My script :

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 350
	money.Parent = leaderstats
end)
1 Like

Can we see the shop script that subtracts the amount of money you have?

1 Like

I assume you want to make an – exchange of Money for Object – service, if that’s your case, you can check if your Player’s Money is greater or equal with

if Player.leaderstats.Money.Value >= Item.Price.Value then
    --[[ TODO: give the Item and substract the Money ]]
    Player.leaderstats.Money.Value -= Item.Price.Value
end

P.D.: @docega075 , if you are using a Client-Server Communication (e.g. RemoteEvent/BindableEvent/[. . .]) make a list of information per item (table); exploiters can manipulate your Event to share unexpected information (in this case, you will probably use replicated items as an argument for your events, and a exploiter can easily fake an Item with a table).

1 Like

I will try everything. Thanks.

Write us the script for your shop please…

Well if you have a lot of debt building u- Oh, I see.

There’s no way this code is causing the issue, can you show what alters the money value of each player?

Here is the button script :

local GUI = script.Parent
local RemoteEvent = game.ReplicatedStorage.CYLINDRE50cc

GUI.Activated:Connect(function()
	RemoteEvent:FireServer()
end)

Here Script Service:

local RemoteEvent = game.ReplicatedStorage.CYLINDRE50cc


game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 350
	money.Parent = leaderstats
end)



RemoteEvent.OnServerEvent:Connect(function(Player)
	Player.leaderstats.Money.Value -= 60
end)

You need to check if they have enough money to do this.

1 Like

Here’s the source of the issue. That’s where you need to place @Misinformater 's code

2 Likes

How should I do it ? a verification ?

You’d do a check to see if the player has enough money, as shown in @Misinformater 's reply.

Like this:

RemoteEvent.OnServerEvent:Connect(function(Player)
    if player.leaderstats.Money.Value >= 60 then
	  Player.leaderstats.Money.Value -= 60
    end
end)

Also take their Client-Server suggestion into consideration.

1 Like

On the blows I had not understood but I see what you mean. I’ll try

1 Like

This depends if you have a plural number (greater than 1) of items.

Thank you very much it works perfectly.

1 Like

Thank you very much for helping me.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.