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
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