Game doesn't subtract my points whenever I buy something from Shop

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

I want to achieve when I buy something, I lose points and be given the item.

  1. What is the issue?

I be given the item but doesn’t reduce my points.

Everything works but the reduction doesn’t.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BuyTools = ReplicatedStorage:WaitForChild("BuyTools")

local function BuyTool(player, tool)
	local Points = player.leaderstats.Time.Value
	local Price = tool.Price.Value

	if Points >= Price then

		Points = Points - Price

		local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()

		giveTool.Parent = player.Backpack

		local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()

		giveTool.Parent = player.StarterGear


That’s probably the problem, what happens is you put a number into the variable (rather than actually defining the variable as a value)

-- example of what I mean
local Points = player.leaderstats.Time.Value -- example 10
print(Points) -- prints 10
Points = 20
print(Points) -- prints 20
print(player.leaderstats.Time.Value) -- prints 10 still

so the fix would just be to define the Points variable to be the instance

	local Points = player.leaderstats.Time -- notice the change
	local Price = tool.Price.Value

	if Points.Value >= Price then -- notice the change

		Points.Value = Points.Value - Price -- notice the change

1 Like

This actually worked wow, but its litteraly the same thing… why does this make a huge change?

Because in the first case what you are doing is saving a number to the variable
.Value gives the actual number value rather than an instance location

local something = game.Workspace.IntValue.Value
print(type(something)) -- "number"

-- That is similar to this
local someNumber = 12345
print(type(someNumber)) -- "number"

-- What we really want is a location reference
local something2 = game.Workspace.IntValue
print(type(something2)) -- "userdata"
1 Like

Now I understand this reason, thank you!