How to make a dropper in a tycoon subtract a leaderstat?

I implimented the changes but now its saying line 8 is indexing nil with waitforchild agein. btw this is my code now

local Values = script.Parent.Parent.Parent.Values

repeat
wait()
until Values.OwnerValue

while wait(3) do
if Values.OwnerValue.Value:WaitForChild(“leaderstats”).Peanuts.Value >= 1 then
local reference = script.Parent:WaitForChild(“reference”)
local drop = game:GetService(“ServerStorage”).PeanutDrop:Clone()
drop.Parent = game.Workspace
drop.Position = reference.Position
drop.Name = “drop”

	local pbamount = Instance.new("NumberValue")
	pbamount.Parent = drop
	pbamount.Name = "pbAmount"
	pbamount.Value = 1

	Values.OwnerValue.Value:WaitForChild("leaderstats").Peanuts.Value -= 1
end

end

Try this instead:

repeat
wait()
until Values.OwnerValue.Value -- Note the .Value at the end
1 Like

TY it works now! it subtracts and then drops :smiley:

1 Like