How to deduct values

Hello!

I need some help with deducting values. In my game, I want my shop to deduct the price of a sword from the players current coins.

I don’t know how to do this so if anyone could help me much would be appreciated.

Thanks!

Your mean like subtraction?
Coins = Coins - Cost

1 Like

Ah, yes, sorry I mean subtraction.

Thanks.

Where are you caught up on it? Do you have a shop script you’re working on or need to modify?

I just need to modify the purchase button.

Post the script/UI details here so we can assist you.

Script inside button:

 script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvents.EquipItem:FireServer(script.Parent.Parent.ItemName.Value)
end)

Server Script:

game.ReplicatedStorage.RemoteEvents.EquipItem.OnServerEvent:Connect(function(plr, item)
	local str = plr.leaderstats.Coins
	local _M = require(game.ReplicatedStorage.Items:FindFirstChild(item).Settings)
	
	if str.Value >= _M.RequiredStrength then
		for i,v in pairs(plr.Backpack:GetChildren()) do
		end
		
		for i,v in pairs(plr.Character:GetChildren())do
			if v:IsA("Tool") then
				v:Destroy()
			end
		end
		
		game.ReplicatedStorage.Items:FindFirstChild(item):Clone().Parent = plr.Backpack
	end
end)

What seems to be the issue with the script? Can you provide any console logs?

There isn’t an issue with the script. I want to know how to subtract the price of the item from the players Coins.

plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value - _M.Price

You’ll need to change Price if the price property has a different name.

1 Like

they already have coins defined in that script

str.Value -= _M.Price

though I would change the name of str to coins or something that makes more sense

str usually means string

EDIT:
forgot to put .Value after str

1 Like

I opted to use “plr.leaderstats.Coins.Value” since “str” as you mentioned is usually in reference to a string.

2 Likes