Hello! I was just curious if there are any ways to detect if the player is touching one of the 3 parts that are in different locations. So for example;
One part is in a group named A, the second one is in a group named B and the other one is in C. If the player touches one of these parts, an event would occur.
I already know how to detect multiple parts that are in the SAME location (using the code given below) in the workspace, but I’m unsure on how to detect the ones that are separated from each other.
for _, part in ipairs(Walls) do -- Walls being the folder that contains the parts that the player is going to touch.
if part:IsA("BasePart") then
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
-- The code would be here.
end)
end
end
You could just table.insert the objects you want into a table, and then iterate through the table instead of just the one workspace folder.
local basepartTable = {}
table.insert(basepartTable, workspace.part)
for i, v in pairs(basepartTable) do
if v:IsA("BasePart") then
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
-- The code would be here.
end)
end
end
So do I just need to write down the names of the parts in the table.insert brackets and if the player touches any of those parts the event would occur?
Only one parameter can be passed through table.insert at a time, so you’d just use table.insert once per object, or embed table.insert into a GetChildren() loop.