Help with backpack container script

Hello community, this is a script of a Tool, that when you click on it gives Coins, the problem is that there is an error with this and the BackPack, when the Tool gives more than the backpack then it is equal to the value of the Tool. How do I do so that it does not put the value of the Tool, but the total of the backpack?

If the Tool gives 100 and
Backpack is 50, then the backpack will be 100/50.

Please help.

Starterpack - Tool - LocalScript:

local Debounce = false
local Tool = script.Parent
local Num = 100
local Player = game.Players.LocalPlayer

Tool.Activated:Connect(function()
	if Debounce == false then
		wait(0.5)
		Debounce = true
		game.ReplicatedStorage.Currencys.Tools.Basic:FireServer(Num)
		if game.Players.LocalPlayer.Bag.Amount.Value >= game.Players.LocalPlayer.Bag.Max.Value then
			game.Players.LocalPlayer.PlayerGui.CurrencyUI.MochilaLlenaFrame.Visible = true
		end
		wait(0.1)
		Debounce = false
	end
end)

Event Remote - Script:

game.ReplicatedStorage.Currencys.Tools.Basic.OnServerEvent:Connect(function(Player, Num)
	if Player.Bag.Amount.Value < Player.Bag.Max.Value then
		Player.Bag.Amount.Value = Player.Bag.Amount.Value + Num
	end
end)

Image:

Screenshot_63

In the code you have to increase the bag stuff, just do

Player.Bag.Amount.Value = math.min(Player.Bag.Amount.Value, Player.Bag.Max.Value)

So if the amount is higher than the max, it will set it to the max

So if the remote is the one that increases it, just do

game.ReplicatedStorage.Currencys.Tools.Basic.OnServerEvent:Connect(function(Player, Num)
	if Player.Bag.Amount.Value < Player.Bag.Max.Value then
		Player.Bag.Amount.Value = math.min((Player.Bag.Amount.Value + Num),Player.Bag.Max.Value)
	end
end)
1 Like

Thank you very much, that’s what I need :slight_smile:

I’m very glad that’s what you needed! If you have anymore issues don’t be afraid to make another post!