The script for tycoon button doesn't work

Here is the script:

local players = game:GetService("Players")
local purchosedSpawn = workspace.Tycoon.Dropper2 --We indicate the dropper
local button = script.Parent --Button for buy dropper
local spawner = purchosedSpawn.DropperPart 
local pricePart = button.Price.PriceGui.PriceValue --Indicate gui
local priceGui =  button.Price.PriceGui.PriceText --Indicate text
local scriptDrop = spawner.Dropper2BlockScript --I IDK what it is for
priceGui.Text = "Buy Dropper - $"..pricePart.Value

local function onHit(hit)
	local tycoon = workspace.Tycoon
	local player = players:GetPlayerFromCharacter(hit.Parent)
	if not player then return end
	print("Function")
	if tycoon.Owner.Value == player then
		if player.leaderstats.Money.Value >= pricePart.Value then
			print("If")
			--player.leaderstats.Money.Value -= pricePart.Value
			for _, Child in 
				ipairs(purchosedSpawn:GetChildren())do
				print("For")
				if Child:IsA("Part") then
					Child.Transparency = 0
					Child.CanCollide = true
					spawner.Transparency = 0.45
					script.Disabled = false
					purchosedSpawn:Destroy()
				end
			end
		end
	end
end
button.Touched:Connect(onHit)

in theory, the for should be prescribed, but it is not written.
I found the code on the Internet and corrected the names to my own.
I don’t know what to do.
Here is the error, the link leads to YouTube
Sorry, my English is very bad, and I’m bad coder

1 Like
   for _, Child in pairs(purchosedSpawn:GetChildren()) do

More info about ipairs and pairs: Whats the Difference Between Ipairs and pairs? - Help and Feedback / Scripting Support - Developer Forum | Roblox

1 Like

the script is not working correctly, I do not know what to do(


the cycle is done 4 times, and then it doesn’t work

1 Like