ok, I have my script to work on my vending machines just fine.
I am now trying to add more script to it so when you click the button it will charge you a set amount (from leaderstats)(cash-storage)
I thought this was set up right but I guess I was wrong. ( I think I know were the problem is but I don't know what to put In it)
I think the problem is on line 3 (Children) but all the files in the parent of script have different names.
any help would be nice, thanks!
script.Parent:WaitForChildren()
for i,v in pairs (script.Parent:GetChildren()) do
v.ClickDetector.MouseClick:connect(function(Click)
local player = game.Players:GetPlayerFromCharacter(Click.Parent)
local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
if cashmoney ~= nil then
if cashmoney.Value >= v.Price.Value then
cashmoney.Value = cashmoney.Value - v.Price.Value
function onClicked(Name, Holder)
local DOF = game.Lighting.DrinkandFood:findFirstChild(Name):clone()
DOF.Parent = game.Workspace
DOF.Handle.CFrame = Holder.CFrame
DOF.Handle.Anchored = false
end
local c = script.Parent:GetChildren()
for i = 1, #c do
if c[i].className == "Part" then
c[i].ClickDetector.MouseClick:connect(function() onClicked(c[i].Name, c[i].Holder)end)
end
wait(0.5) -- Time to wait in between clicks
end
end
end
end)
end

6 comments
You shouldn't have spaces for methods.
It's not good style, but there's no real problem with putting spaces there (other than not doing it consistently)
Line 3 should be v.ClickDetector.MouseClick assuming all the children have click detectors.
ok, i made those changes but still dont work
ok it gave me an error about the wait for child so i removed it. now it is giving me an error on the clickeddetector, but all buttons have one...10:59:06.541 - ClickDetector is not a valid member of Script
10:59:06.541 - Script 'Workspace.Tycoons.Brightblue.PurchasedObjects.VendingMachin', Line 5