I wanted to make a surfacegui Shop but the points isn't subtracted and the item isn't given
local buyer = game.Players
cash = buyer:FindFirstChild("leaderstats")
local tool = game.Lighting:FindFirstChild("BloxyCola") -- put the excact weapon name here. the weapon has to be in game Lighting
function buy()
if cash ~= nil then
local points = cash:FindFirstChild("Points")
if points.Value < 5 then return end -- Cost
if points.Value >= 5 then -- Cost
local b = game.Lighting("BloxyCola"):clone() -- Tool Given
b.Parent = buyer.StarterGear
points.Value = points.Value - 5 -- Cost
end
end
end
script.Parent.MouseButton1Down:connect(buy)
Error:Workspace.Part.SurfaceGui.Button.Main:6: attempt to index global 'cash' (a nil value)
Why won't it work?

1 comment
Since you refereed to the Cost(5) 3 time's, you could have used a variable for it for easier editing.