I cant find anything about part touching part. Im talking about that if part touched another part then something happens . Plz write in answers. :-
COMMUNITY QUESTION
How to make touch event on parts?
2 answers
To do a touched event, you could write it like this (as an anonymous function).
--// This script must be inside of your part
script.Parent.Touched:Connect(function(hit) --// If the script's parent (the part) is touched then it will connect this function and log what hit it (logged through the "hit" parameter).
-- Put what happens here (i.e. transparency changes, brickcolor changes, etc.
end)
Code you need:
function OnTouch(hit)
--your code here
script.Parent.Touched:Connect(OnTouch)
Example of use (my fire script):
local val = 0
function OnTouch(hit)
local head = hit.Parent:FindFirstChild("Head")
local human = hit.Parent:FindFirstChild("Humanoid")
if human ~= nil then
local GC = hit.Parent:GetChildren()
for i, v in pairs(GC) do
if v:IsA("BasePart") then
if v:FindFirstChild("FireEmmiter") == nil then
local Particle = script.Parent:FindFirstChild("FireEmmiter")
local ParticleClone = Particle:Clone()
ParticleClone.Parent = v
val = val + 1
if val == 16 then
val = 0
while true do
wait(0.025)
human.Health = human.Health - 1
if human.Health == 0 then
local s = hit.Parent:FindFirstChild("Shirt")
local p = hit.Parent:FindFirstChild("Pants")
for i, v in pairs(GC) do
if v:IsA("Accessory") then
v:ClearAllChildren()
else if v:IsA("BasePart") then
v.Material = Enum.Material.Slate
v.Color = Color3.fromRGB(27, 42, 53)
if s ~= nil then
s:Destroy()
if p ~= nil then
p:Destroy()
end
end
end
end
end
end
end
end
end
end
end
end
end
script.Parent.Touched:Connect(OnTouch)
1 comment
0
i dont understand the code but the answer is helpful cause i can learn about that and then i will understand the code :D
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
THX! i dont know why i dont knowed about that despite that i knowed about the touched event but THX for realising about that!
Please accept my response if it helped you/solved your problem. :)