Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make touch event on parts? [closed]

Asked by 4 years ago

I cant find anything about part touching part. Im talking about that if part touched another part then something happens . Plz write in answers. :-

Closed as Not Constructive by itz_rennox, Torren_Mr, User#29913, zblox164, and JesseSong

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
2
Answered by 4 years ago

To do a touched event, you could write it like this (as an anonymous function).

1--// This script must be inside of your part
2 
3script.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).
4 
5-- Put what happens here (i.e. transparency changes, brickcolor changes, etc.
6 
7end)
0
THX! i dont know why i dont knowed about that despite that i knowed about the touched event but THX for realising about that! JasiuJasiuB 13 — 4y
0
Please accept my response if it helped you/solved your problem. :) ParticularlyPenguin 71 — 4y
Ad
Log in to vote
0
Answered by
Axenori 124
4 years ago

Code you need:

1function OnTouch(hit)
2--your code here
3script.Parent.Touched:Connect(OnTouch)

Example of use (my fire script):

01local val = 0
02function OnTouch(hit)
03    local head = hit.Parent:FindFirstChild("Head")
04    local human = hit.Parent:FindFirstChild("Humanoid")
05    if human ~= nil then
06        local GC = hit.Parent:GetChildren()
07        for i, v in pairs(GC) do
08            if v:IsA("BasePart") then
09                if v:FindFirstChild("FireEmmiter") == nil then
10                local Particle = script.Parent:FindFirstChild("FireEmmiter")
11                local ParticleClone = Particle:Clone()
12                ParticleClone.Parent = v
13                val = val + 1
14                if val == 16 then
15                val = 0
View all 45 lines...
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 JasiuJasiuB 13 — 4y