I'm having issues with Touched events

I am not familiar with the Tycoon Kit, but could you please send an image of the output! It is easier to find a problem that way.

Also could you send an image/explain where the scripts are?

For the Output:

There isn’t anything named in there inside Purchases when using WaitForChild(), resulting in a infinite loop

You have to change the names of them in order to prevent that from happening

The Dropper Script seems fine, but since this is an old Kit you’ll need to work around changing the script a little bit:

local function onPartTouched(otherPart)
	print("Testing")
	if otherPart == script.Parent.Parent.Parent.Essentials.Conveyor.CollectorPit.TopLayer then
		print("Hello?")
		local CurrencyToCollect = script.Parent.Parent.Parent.CurrencyToCollect.Value
		local Amount = script.Parent.Parent.Parent.Essentials.CollectorParts.Display.GUI.Amount.Text
		partParent:Destroy()
		CurrencyToCollect += script.Parent.Crystal.Cash.Value
		Amount = ("$"..CurrencyToCollect)
	end	
end

I’m preferably looking at this line here:

if otherPart == script.Parent.Parent.Parent.Essentials.Conveyor.CollectorPit.TopLayer then

Since there really isn’t a name detection for the otherPart variable, I’m assuming it just skips through that rest of the code

You could try this and see if that’ll work:

local function onPartTouched(otherPart)
	print("Testing")
	if otherPart.Name == "TopLayer" then --You'll need to configure around the name a bit
		print("Hello?")
		local CurrencyToCollect = script.Parent.Parent.Parent.CurrencyToCollect.Value
		local Amount = script.Parent.Parent.Parent.Essentials.CollectorParts.Display.GUI.Amount.Text
		partParent:Destroy()
		CurrencyToCollect += script.Parent.Crystal.Cash.Value
		Amount = ("$"..CurrencyToCollect)
    else
        print("Not the right part")
	end	
end

Ok. I tried your idea. The output is:

Oh wait

repeat wait() until script.Parent.Parent.Name == "PurchasedObjects"

image

script.Parent.Parent.Name is referring to the Purchases Model, not the PurchasedObjects

That dropper gets moved to “PurchasedObjects” when it is purchased.

Try this?

repeat 
    wait() 
    print("Waiting")
until script.Parent.Parent.Name == "PurchasedObjects"

Same result as last time, except that “Waiting” gets printed once.

Excuse me? Why am I no longer getting any help with this? The problem isn’t even solved!

Are there any other WaitForChild events besides the one in the code you sent?

Quite a few! Three scripts have them!

Purchase Handler:

	--[[
		All configurations are located in the "Settings" Module script.
		Please don't edit this script unless you know what you're doing.
	--]]
	local Objects = {}
	local TeamColor = script.Parent.TeamColor.Value
	local Settings = require(script.Parent.Parent.Parent.Settings)
	local Money = script.Parent.CurrencyToCollect
	local Debris = game:GetService('Debris')
	local Stealing = Settings.StealSettings
	local CanSteal = false -- don't change or else you won't be able to steal currency
	
	script.Parent.Essentials.Spawn.TeamColor = TeamColor
	script.Parent.Essentials.Spawn.BrickColor = TeamColor
	
	function Sound(part,id)
		if part:FindFirstChild('Sound') then
			return
		else
			local Sound = Instance.new('Sound',part)
			Sound.SoundId = "rbxassetid://"..tostring(id)
			Sound:Play()
			delay(Sound.TimeLength, function()
				Sound:Destroy()
			end)
		end
	end
	
	--Parts that fall into the collector(s) get processed
	for i,v in pairs(script.Parent.Essentials:GetChildren()) do
		if v.Name == "PartCollector" then
			v.Touched:connect(function(Part)
				if Part:FindFirstChild('Cash') then
					Money.Value = Money.Value + Part.Cash.Value
					Debris:AddItem(Part,0.1)
				end
			end)
		end
	end
	
	--Player Touched Collector processor
	deb = false
	script.Parent.Essentials.Giver.Touched:connect(function(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player ~= nil then
			if script.Parent.Owner.Value == player then
				if hit.Parent:FindFirstChild("Humanoid") then
					if hit.Parent.Humanoid.Health > 0 then
						if deb == false then
							deb = true
							script.Parent.Essentials.Giver.BrickColor = BrickColor.new("Bright red")
							local Stats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
							if Stats ~= nil then 
							Sound(script.Parent.Essentials, Settings.Sounds.Collect)
							Stats.Value = Stats.Value + Money.Value
							Money.Value = 0
							wait(1)
							script.Parent.Essentials.Giver.BrickColor = BrickColor.new("Sea green")
							deb = false
							end
						end
					end
				end
			elseif Stealing.Stealing then -- if player isn't owner and stealing is on
				if CanSteal == true then
					CanSteal = false
					delay(Stealing.PlayerProtection, function()
						CanSteal = true
					end)
					if hit.Parent:FindFirstChild("Humanoid") then
						if hit.Parent.Humanoid.Health > 0 then
							local Stats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
							if Stats ~= nil then
								local Difference = math.floor(Money.Value * Stealing.StealPrecent)
								Sound(script.Parent.Essentials, Settings.Sounds.Collect)
								Stats.Value = Stats.Value + Difference
								Money.Value = Money.Value - Difference
							end
						end
					end
				else
					Sound(script.Parent.Essentials, Settings.Sounds.Error)
				end
			end
		end
	end)
	
	script.Parent:WaitForChild("Buttons")
	for i,v in pairs(script.Parent.Buttons:GetChildren()) do
		spawn(function()
		if v:FindFirstChild("Head") then
			
			local ThingMade = script.Parent.Purchases:WaitForChild(v.Object.Value)
			if ThingMade ~= nil then
				Objects[ThingMade.Name] = ThingMade:Clone()
				ThingMade:Destroy()
			else
				--//Button doesn't have object, remove it
				error('Object missing for button: '..v.Name..', button has been removed')
				v.Head.CanCollide = false
				v.Head.Transparency = 1
			end
									
			if v:FindFirstChild("Dependency") then --// if button needs something unlocked before it pops up
				v.Head.CanCollide = false
				v.Head.Transparency = 1
				coroutine.resume(coroutine.create(function()
					if script.Parent.PurchasedObjects:WaitForChild(v.Dependency.Value) then
						if Settings['ButtonsFadeIn'] then
							for i=1,20 do
								wait(Settings['FadeInTime']/20)
								v.Head.Transparency = v.Head.Transparency - 0.05
							end
						end
						v.Head.CanCollide = true
						v.Head.Transparency = 0
					end
				end))
			end
			
			v.Head.Touched:connect(function(hit)
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if v.Head.CanCollide == true then
					if player ~= nil then
						if script.Parent.Owner.Value == player then
							if hit.Parent:FindFirstChild("Humanoid") then
								if hit.Parent.Humanoid.Health > 0 then
									local PlayerStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
									if PlayerStats ~= nil then
										if (v:FindFirstChild('Gamepass')) and (v.Gamepass.Value >= 1) then
											if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,v.Gamepass.Value) then
												Purchase({[1] = v.Price.Value,[2] = v,[3] = PlayerStats})
											else
												game:GetService('MarketplaceService'):PromptPurchase(player,v.Gamepass.Value)
											end
										elseif (v:FindFirstChild('DevProduct')) and (v.DevProduct.Value >= 1) then
											game:GetService('MarketplaceService'):PromptProductPurchase(player,v.DevProduct.Value)
										elseif PlayerStats.Value >= v.Price.Value then
											Purchase({[1] = v.Price.Value,[2] = v,[3] = PlayerStats})
											Sound(v, Settings.Sounds.Purchase)
										else
											Sound(v, Settings.Sounds.ErrorBuy)
										end
									end
								end
							end
						end
					end
				end
			end)
			end
		end)
	end
	
	function Purchase(tbl)
		local cost = tbl[1]
		local item = tbl[2]
		local stats = tbl[3]
		stats.Value = stats.Value - cost
		Objects[item.Object.Value].Parent = script.Parent.PurchasedObjects
		if Settings['ButtonsFadeOut'] then
			item.Head.CanCollide = false
			coroutine.resume(coroutine.create(function()
				for i=1,20 do
					wait(Settings['FadeOutTime']/20)
					item.Head.Transparency = item.Head.Transparency + 0.05
				end
			end))
		else
			item.Head.CanCollide = false
			item.Head.Transparency = 1
		end
	end
	
	function Create(tab)
		local x = Instance.new('Model')
		Instance.new('NumberValue',x).Value = tab[1]
		x.Value.Name = "Cost"
		Instance.new('ObjectValue',x).Value = tab[2]
		x.Value.Name = "Button"
		local Obj = Instance.new('ObjectValue',x)
		Obj.Name = "Stats"
		Obj.Value = tab[3]
		x.Parent = script.Parent.BuyObject
	end
	
	--// This was very rushed and is inefficent; if you plan on making something like this don't use a child added listener.
	script.Parent:WaitForChild('BuyObject').ChildAdded:connect(function(child)
		local tab = {}
		tab[1] = child.Cost.Value
		tab[2] = child.Button.Value
		tab[3] = child.Stats.Value
		Purchase(tab)
		wait(10)
		child:Destroy()
	end)

Dev Product (Gamepass buttons?) handler:

local Settings = require(script.Parent.Settings)
local Tycoon = script.Parent.Tycoons:GetChildren()[1]
script.Parent = game.ServerScriptService
local DevProducts = {}
local MarketplaceService = game:GetService('MarketplaceService')

for i,v in pairs(Tycoon:WaitForChild('Buttons'):GetChildren()) do
	if v:FindFirstChild('DevProduct') then
		if v.DevProduct.Value > 0 then
			DevProducts[v.DevProduct.Value] = v -- the button
		end
	end
end

MarketplaceService.ProcessReceipt = function(receiptInfo)
	for i,plr in pairs(game.Players:GetPlayers()) do
		if plr.userId == receiptInfo.PlayerId then
			if DevProducts[receiptInfo.ProductId] then
				local obj = DevProducts[receiptInfo.ProductId]
				local PlrT = game.ServerStorage.PlayerMoney:WaitForChild(plr.Name).OwnsTycoon
				if PlrT.Value ~= nil then
					--if PlrT.Value.PurchasedObjects:FindFirstChild(obj.Object.Value) == false then
						local PlayerStats = game.ServerStorage.PlayerMoney:FindFirstChild(plr.Name)
						Create({[1] = 0,[2] = obj,[3] = PlayerStats}, PlrT.Value.BuyObject)
					--end
				end
			end
		end
	end
end

function Create(tab, prnt)
	local x = Instance.new('Model')
	Instance.new('NumberValue',x).Value = tab[1]
	x.Value.Name = "Cost"
	Instance.new('ObjectValue',x).Value = tab[2]
	x.Value.Name = "Button"
	local Obj = Instance.new('ObjectValue',x)
	Obj.Name = "Stats"
	Obj.Value = tab[3]
	x.Parent = prnt
end

Core Handler:

--[[
	All configurations are located in the "Settings" Module script.
	Please don't edit this script unless you know what you're doing.
--]]

local Tycoons = {}
local Teams = game:GetService('Teams')
local Settings = require(script.Parent.Settings)
local BC = BrickColor
local Storage = Instance.new('Folder', game.ServerStorage)
Storage.Name = "PlayerMoney"
Instance.new('Model',workspace).Name = "PartStorage" --  parts dropped go in here to be killed >:)

function returnColorTaken(color)
	for i,v in pairs(Teams:GetChildren()) do
		if v:IsA('Team') then
			if v.TeamColor == color then
				return true
			end
		end
	end
	return false
end
--run this first so if there is a 'white' team it is switched over
if not Settings['AutoAssignTeams'] then
	local teamHire = Instance.new('Team', Teams)
	teamHire.TeamColor = BC.new('White')
	teamHire.Name = "For Hire"
end

for i,v in pairs(script.Parent:WaitForChild('Tycoons'):GetChildren()) do
	Tycoons[v.Name] = v:Clone() -- Store the tycoons then make teams depending on the tycoon names
	if returnColorTaken(v.TeamColor) then
		--//Handle duplicate team colors
		local newColor;
		repeat
			wait()
			newColor = BC.Random()
		until returnColorTaken(newColor) == false
		v.TeamColor.Value = newColor
	end
	--Now that there are for sure no duplicates, make your teams
	local NewTeam = Instance.new('Team',Teams)
	NewTeam.Name = v.Name
	NewTeam.TeamColor = v.TeamColor.Value
	if not Settings['AutoAssignTeams'] then
		NewTeam.AutoAssignable = false
	end
	v.PurchaseHandler.Disabled = false
end

function getPlrTycoon(player)
	for i,v in pairs(script.Parent.Tycoons:GetChildren()) do
		if v:IsA("Model") then
			if v.Owner.Value == player then
				return v
			end
		end
	end
	return nil
end

game.Players.PlayerAdded:connect(function(player)
	local plrStats = Instance.new("NumberValue",game.ServerStorage.PlayerMoney)
	plrStats.Name = player.Name
	local isOwner = Instance.new("ObjectValue",plrStats)
	isOwner.Name = "OwnsTycoon"
end)

game.Players.PlayerRemoving:connect(function(player)
	local plrStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
	if plrStats ~= nil then
		plrStats:Destroy()
	end
	local tycoon = getPlrTycoon(player)
	if tycoon then
		local backup = Tycoons[tycoon.Name]:Clone()
		tycoon:Destroy()
		wait()
		backup.Parent=script.Parent.Tycoons
	end
end)

I don’t dare edit these scripts if the WaitForChild events are causing errors because they are so complex and this is my first game that I am trying to create here.

I believe it has to be this since it’s similar oto the infinite yields you’re having, try changing it to

local ThingMade = script.Parent.Purchases:WaitForChild(v.Object.Value,5)

The number I placed is the timeOut, if after 5 seconds in this case the thing was not found, return nil

I got an error (well… two, but they are from the same line): Workspace.Tycoons.Yellow.PurchaseHandler:99: Object missing for button: Upgrade Walls - [$350], button has been removed

Workspace.Tycoons.Yellow.PurchaseHandler:99: Object missing for button: Buy Dropper1v1 - [$70], button has been removed

This error takes me to the Purchase Handler, line 99.

I think the issue is that you didn’t sent any object to be set when you buy the button, there’s nothing for it to use so the buttosn are useless

Ok, how do I fix this? Do I remove the ‘, 5’ from the WaitForChild event? (Does this error have anything to do with having to claim the tycoon before getting buttons? I didn’t mean to touch those buttons.)

The error has to do with the buttons not having an object connected to it when you buy it, it’s a custom error the creator made. I’m not sure how you’d do taht since I never used the kit

Well… I might not have assigned purchases for all the droppers and have done very few alterations (almost none) to these scripts and I did not assign purchases to things like wall upgrades.

Ok. I assigned droppers to the dropper purchases and am only getting errors from the wall purchases (possibly an upgrader purchase, but i did not assign a purchase of that kind).

Also, I noticed that when I assigned parts, the other dropper buttons did not appear after I bought the first dropper.

I decided to insert the following script into the crystal model (called “Clonable”):

local part = script.Parent.Crystal
local CurrencyToCollect = script.Parent.Parent.Parent.Parent.Essentials.CollectorParts.Display.CurrencyToCollect
local Amount = script.Parent.Parent.Parent.Parent.Essentials.CollectorParts.Display.GUI.Amount

local function onPartTouched(otherPart)
	print(part.Name .. " has touched " .. otherPart.Name)
	if otherPart.Name == "PartCollector" then
		CurrencyToCollect = CurrencyToCollect + script.Parent.MoneyValue.Value
		Amount.Text = CurrencyToCollect
		script.Parent:Destroy()
	end
end

part.Touched:Connect(onPartTouched)