Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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
Ad

Answer this question