Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do make a gui show up when parts are touched(more then 1 part)?

This is what i have tryed so far but it does not seem to work

Interactions = workspace:GetChildren("Interaction")
for i = 1,#Interactions do
for i,v in pairs(Interactions) do
v.Touched:connect(function()
print("Something")
end)
end
end

1 answer

✓ Accepted answer

You are using GetChildren() wrong. GetChildren() requires no arguments. This means that you do not need to put anything in the parentheses. It will return a read-only table of all the children in whatever it was called on. You have to make the entire path to 'Interaction', then call GetChildren()on that.

Also, there is no need for two for loops. All you're accomplishing by that is adding lag, or in some situations, making your code not work properly.

local interactions = workspace.Interaction:GetChildren()

for i,v in pairs(interactions) do
	v.Touched:connect(function(hit)
		print("Something")
	end
end

Or, with a numeric for loop,

local interactions = workspace.Interaction:GetChildren()

for i = 1, #interactions do
	interactions[i].Touched:connect(function(hit)
		print("Something")
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.