Tycoon Collector Multiple Names

If I try to add multiple names to “collect” the mesh for money, the entire script does not work. “Visor2007” is the one that functions.

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

script.Parent.Touched:Connect(function(Hit)
	if Hit.Name == "Visor2007" and Hit:FindFirstChild("CashValue") then
		CashValue.Value += Hit:FindFirstChild("CashValue").Value
		Hit:Destroy()
	end
end)

This is my current work around but is it efficient enough when I have to add hundreds of names?

if Hit.Name == "Part" or "Visor2007" and Hit:FindFirstChild("CashValue") then

You could use a table.

local Names = {"Visor2007"}
local CashValue = script.Parent.Parent.Parent.Parent.Values.CashValue

script.Parent.Touched:Connect(function(Hit)
	if table.find(Names, Hit.Name) and Hit:FindFirstChild("CashValue") then
		CashValue.Value += Hit:FindFirstChild("CashValue").Value
		Hit:Destroy()
	end
end)
1 Like

If all your meshes had the child “CashValue”, you could just get rid of the first part of the IF statement and just do if Hit:FindFirstChild("CashValue") then because it’s highly unlikely a mesh that is not supposed to give money would have that child.

This would save you from having to add hundreds of names, like you said you would need to do.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.