I need to make a script so when a part (Part1) touches another part (Part2), a decal is added to part 1.
✓ ANSWER ACCEPTED
Decal Part When Touched?
1 answer
✓ Accepted answer
This is the basic knowledge for beginners. I won't go through the bulk explanations, learn it through the codes.
local Part1 --Your part1
local Part2 --Your part2
local DECAL_ID = "rbxassetid://ID_HERE"--Type Id here, you know how.
local DECAL_FACING = Enum.NormalId.Front--[[Decal facing direction.((Related Vector3))--]]
local DECAL_TRANSPARENCY = 0;--[[1 = Invisible, 0 = Visible--]]
--[[There are two methods:Part1 touches Part2 or Part2 touches Part1
My method is Part2 touches Part1.
-]]
Part2.Touched:Connect(function(part)
if part and part == Part1 and not part:FindFirstChildWhichIsA("Decal") then
print("Part2 touched Part1, Part1 has no decal, adding decal!")
local decal = Instance.new("Decal",Part1)
decal.Face = DECAL_FACING
decal.Texture = DECAL_ID
decal.Transparency = DECAL_TRANSPARENCY
end
end)
After this, we can convert it into a function:
-----------ESTABLISHING EVENT FUNCTIONS
local Established = {}
function Establish_TouchEvent(p1,p2,DECAL_ID,DECAL_FACING,DECAL_TRANSPARENCY)
--We use p1 as a key, p2 as a value.
--Which won't cause any overlapping problems
if not (Established[p1] == p2 or p1 == nil or p2 == nil) then
Established[p1] = p2
p2.Touched:Connect(function(part)
if part and part == p1 and not part:FindFirstChildWhichIsA("Decal") then
local decal = Instance.new("Decal",p1)
decal.Face = DECAL_FACING
decal.Texture = DECAL_ID
decal.Transparency = DECAL_TRANSPARENCY
end
end)
end
end
Use it like this:
Establish_TouchEvent(p1,p2,"your decal id",Enum.NormalId you know,Transparency)
More details: BasePart.Touched
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Look into TouchInterest and how instances can be created, reparented, etc.
You may want to approve my solution. :))