Hi! I hope this is not asked before, I have tried to search and did not find it.
I wanted to have one single script that manages the Touched event for every part contained in a folder. So I coded this:
local folder = workspace:WaitForChild("Partes")
local parts = folder:GetChildren()
function cargar(part)
-- whatever the function does
end
for _, part in ipairs(parts) do
part.Touched:Connect(cargar)
end
My question is: Is there any way of knowing which basepart raised the event? Or the only way to do that is placing multiple scripts as children of each part?
local folder = workspace:WaitForChild("Partes")
local parts = folder:GetChildren()
function cargar(partTocuhed, part) -- Now the first argument is the part that touched me, and part is the party that the player/part touched.
-- whatever the function does
end
for _, part in ipairs(parts) do
part.Touched:Connect(function(partTocuhed) cargar(partTocuhed, part) end)
end
I’m not sure I follow, you stated that you wanted to know which “BasePart” raised the Event (Which my assumption is that you’re not wanting to check for the Part that got touched provided by the Touched Event)
My first language is not English, let me try again. There are several bricks on the floor (parts in the folder) and the character touches one of them with the left foot. The Touched event has the information of the left foot in the parameter called part, but my question is: can I get which one of the bricks was touched?
I think I understand, it is possible but the only issue is that you can’t pass additional parameters/arguments, only the ones that are provided by the Events themselves so you’ll have to find some workaround in order to get the Part that got touched inside the Folder itself
local folder = workspace:WaitForChild("Partes")
local parts = folder:GetChildren()
for _, part in ipairs(parts) do
part.Touched:Connect(function(TouchedPart)
print("Part that activated the Touched Event: "..TouchedPart)
print("Part that started the Touched Event: "..part.Name)
end)
end