I am trying to make a light change by a vehicle, this is what i need:
If a part with a specific name, touches another part (The script’s parent.), something will change.
Keep in mind. the part with the specific name are in multiple models.
local part_script = script.Parent -- the script's parent part
local part_other_name = string -- all parts with this name will be detected
part_script.Touched:Connect(function(part_incoming)
if part_incoming.Name == part_other_name then
print("Part touched", part_incoming)
end
end)
If you want to go a step further in making sure only selected parts can touch, you could either use Attributes or CollectionService to give attributes / tags to specific objects (parts in this case) only.
-- Attributes
local part_script = script.Parent -- the script's parent part
local part_other_attribute = string -- all parts with this attribute set to true will be detected
part_script.Touched:Connect(function(part_incoming)
if part_incoming:GetAttribute(part_other_attribute) then
print("Part touched", part_incoming)
end
end)