I have a function, with multiple connections.
Because I’d like this script to be softcoded, and not require changing the script (the properties of the mechanism are specified in a table), I’d like to know if it’s possible to know which part was touched or clicked, so that depending on where that part is specified in the table, different things can happen.
function InputFunction(Hit)
--print(touched/clicked part)
end
for i,v in pairs(Input:GetDescendants()) do
if v:IsA("ClickDetector") then
v.MouseClick:Connect(InputFunction)
elseif v:IsA("Part") and v.Parent:IsA("Folder") then
v.Touched:Connect(InputFunction)
end
end
function InputFunction(Hit)
--print(touched/clicked part)
end
for i,v in pairs(Input:GetDescendants()) do
if v:IsA("ClickDetector") then
v.MouseClick:Connect(function() InputFunction(v.Parent) end)
elseif v:IsA("Part") and v.Parent:IsA("Folder") then
v.Touched:Connect(function(hit) InputFunction(hit) end)
end
end
Yes, that did the trick.
On line 9, I removed the first “hit” and replaced the 2nd one with “v”, because otherwise it just outputs the person or part that touched.
Thank you.