Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't surfacegui Shop button give tools?

Asked by
yoshi8080 445 Moderation Voter
9 years ago

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 answer

Log in to vote
3
Answered by
xuefei123 214 Moderation Voter
9 years ago

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)
1
Since you refereed to the Cost(5) 3 time's, you could have used a variable for it for easier editing. ISellCows 2 — 9y
Ad

Answer this question