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?
You have to find the players folder in players, not
game.Players
You should use a local script; Put it in StarterGui or StarterPack
local buyer = game.Players.LocalPlayer local part = game.Workspace.Part.SurfaceGui.TextButton--obviously change the names. 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 part.MouseButton1Down:connect(buy)