Multiple Cash Collectors

You can write your topic however you want, but you need to answer these questions:

  1. **What do you want to achieve? I want to have multiple CashCollectors in my Tycoon, which spawn when buying the next Floor

  2. **What is the issue? Every CashCollector (except1) doesnt work and doesnt react to being touched.

  3. **What solutions have you tried so far? Looked for the issue(dont get the .Touched), tried different ways of refferring

So I have a Tycoon where all Items you buy get cloned into the Folder Purchases, but the CashCollector there doesnt work(see images)

tycoon.MainItems.CashCollector.Button.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
if values.OwnerValue.Value == player then
if player.Character.Humanoid.Health > 0 then
mainItems.CashCollector.Button.BrickColor = BrickColor.new(“Really red”)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + values.MoneyValue.Value
values.MoneyValue.Value = 0
playSound(mainItems.CashCollector, audio.CashSound.SoundId)
task.wait(1)
mainItems.CashCollector.Button.BrickColor = BrickColor.new (“Lime green”)
end
end
end
end)

tycoon.Purchases.Floor1.CashCollector.Button.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
if values.OwnerValue.Value == player then
if player.Character.Humanoid.Health > 0 then
tycoon.Purchases.Floor1.CashCollector.Button.BrickColor = BrickColor.new(“Really red”)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + values.MoneyValue.Value
values.MoneyValue.Value = 0
playSound(tycoon.Purchases.Floor1.CashCollector, audio.CashSound.SoundId)
task.wait(1)
tycoon.Purchases.Floor1.CashCollector.Button.BrickColor = BrickColor.new (“Lime green”)
end
end
end
end)

The one in mainItems work but the other one doesnt
Bildschirmfoto 2024-07-29 um 20.01.22
Bildschirmfoto 2024-07-29 um 20.01.54
Bildschirmfoto 2024-07-29 um 20.01.43

Try placing print(“whatever”) into places where important things happen (like when parts touch the collector) and see what happens. Also for future reference use the preformatted text option to make the code more readable.

this type of thing

so the problem is already at the touching, the touch dont get detected and how do i do this text thing?

Ctrl-E or the button above the text box that looks like </>

Try separating the Core script and giving every collector its own script.

You type this symbol 3x at the start, and 3x at the end: `

-- your code

image

Code for everyone who needs it

tycoon.MainItems.CashCollector.Button.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player ~= nil then
		if values.OwnerValue.Value == player then
			if player.Character.Humanoid.Health > 0 then
				mainItems.CashCollector.Button.BrickColor = BrickColor.new(“Really Red”)
				player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + values.MoneyValue.Value
				values.MoneyValue.Value = 0
				playSound(mainItems.CashCollector, audio.CashSound.SoundId)
				task.wait(1)
				mainItems.CashCollector.Button.BrickColor = BrickColor.new mainItems.CashCollector.Button.BrickColor = BrickColor.new (“Lime green”)
			end
		end
	end
end)

tycoon.Purchases.Floor1.CashCollector.Button.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player ~= nil then
		if values.OwnerValue.Value == player then
			if player.Character.Humanoid.Health > 0 then
				tycoon.Purchases.Floor1.CashCollector.Button.BrickColor = BrickColor.newmainItems.CashCollector.Button.BrickColor = BrickColor.new(“Really Red”)
				player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + values.MoneyValue.Value
				values.MoneyValue.Value = 0
				playSound(tycoon.Purchases.Floor1.CashCollector, audio.CashSound.SoundId)
				task.wait(1)
				tycoon.Purchases.Floor1.CashCollector.Button.BrickColor = BrickColor.new (“Lime green”)
			end
		end
	end
end)

What you have to do is to see where it goes wrong, so you should place print or warns to wherever you suspect.

For example the part where it checks if its a player or not, or checking if the owner is player etc.

Also the brickcolors strings seem to be gray for me, for some reason. Maybe it doesn’t change the color?

hey the problem is already at the detection of the .touched