so im making a small tycoon and instead of using on touch bricks like most im using a GUI button system (i hope) so ive got a tycoon kit and am trying to convert the ontouch brick into a clickable GUI button, im pretty bad at lua so idk what im doing.
the problem with my button is in the output it says attempting to call a nil value (hit) on line 16,
i dont know how to fix this, i want this to work as a button to buy the part like in a tycoon
-------------------------------------------------------------------------------------------------------------------------
model = workspace.Tycoon.Factory.Part2
Upgradecost = 0
-------------------------------------------------------------------------------------------------------------------------
upgradeStuff = model:clone()
wait(1)
model:remove()
owner = workspace.Tycoon.Factory.OwnerName
local ting = 0
function Click(hit)
if ting == 0 then
ting = 1
check = hit.Parent:FindFirstChild("Humanoid")
if check ~= nil then
if hit.Parent.Name == owner.Value then
local user = game.Players:GetPlayerFromCharacter(hit.Parent)
local stats = user:findFirstChild("leaderstats")
if stats ~= nil then
local cash = stats:findFirstChild("Gold")
if cash.Value > (Upgradecost-1) then
cash.Value = cash.Value - Upgradecost
upgradeStuff.Parent = script.Parent.Parent.Parent
script.Parent:remove()
end
end
end
end
ting = 0
end
end
script.Parent.MouseButton1Click:connect(Click)
