Shop not working

I am trying to make a simple shop using a proximity prompt, the tool is being given to the player, but the player is not losing money

local item = game.ServerStorage["item"]
script.Parent.Triggered:Connect(function(player)
	local Ls = player:WaitForChild("leaderstats")
	local coins = Ls:WaitForChild("Coins").Value
	if coins >= 10 then
		coins = coins - 10
	local inv = player.Backpack
	local clone = item:Clone()
	clone.Parent = inv
	end
end)
1 Like

thats because you are only decreasing the variable coins. not the players amount in leadstats. Here is a fixed script:

local item = game.ServerStorage["item"]
script.Parent.Triggered:Connect(function(player)
	local Ls = player:WaitForChild("leaderstats")
	local coins = Ls:WaitForChild("Coins") --Deleted .Value
	if coins.Value >= 10 then --Added .Value after coins
		coins.Value = coins.Value - 10 --Added .Value after coins
	local inv = player.Backpack
	local clone = item:Clone()
	clone.Parent = inv
	end
end)

I changed the coins variable to be the number/integer instance instead and added .Value after all places where coins was mentioned.

1 Like