My script starts off with 0 oats. People drop off oats to the part and the oat variable goes up by 1. That bit works. But then the give function doesn't work when I try to pick up a tool. Before I added the "if oats > 0 then," I could pick up the tool so I know that bit works. Here is my script:
oats = 0
print(oats)
function tch(h)
if (h.Parent.Oats.Name == "Oats") then
oats = oats + 1
h.Parent:Destroy()
script.Parent.Parent.OatCount.SurfaceGui.TextLabel.Text = oats
print(oats)
end
end
script.Parent.Touched:connect(tch)
function onClicked()
if oats > 0 then -- the following does not run
function give(dough)
local y = dough.Backpack
local z = game.Lighting["Handful of Oats"]
z:Clone().Parent = y
end
end
end
script.Parent.ClickDetector.MouseClick:connect(give)
script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 comments
It works! Thank you for help, I really appreciate it!
No problem.