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

how to check a specific part touches another part?

Asked by
AIexR32 11
4 years ago
local part = script.Parent
local part2 = script.Parent.Parent.Specificpart

local function onTouch(part)
    print("Touch started: " .. part.Name)
    part2.Size = Vector3.new(4,4,4)
end

local function onTouchEnded(part)
    print("Touch ended: " .. part.Name)
    part2.Size = Vector3.new(1,4,1)
end

part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)

when i someone touching "part" then"part2" changes his size i want - part2 touches part and part2 changing his size how i check part2 touching part

0
Call GetTouchingParts(), use a for loop to check for the part's name, and then do something when that name has been reached DeceptiveCaster 3761 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

To do this you need to add what is called an if statement. An if statement checks whether an argument is true or false.

Here is what you would do:

local part = script.Parent
local part2 = script.Parent.Parent.Specificpart

local function onTouch(part)
    print("Touch started: " .. part.Name)
     if part == part2 then print("Part is the same") end
    part2.Size = Vector3.new(4,4,4)
end

local function onTouchEnded(part)
    print("Touch ended: " .. part.Name)
    part2.Size = Vector3.new(1,4,1)
end

part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
Ad
Log in to vote
0
Answered by 4 years ago

You can get the hitted part's name:

script.Parent.Touched:Connect(function(hit)
    if hit.Name == "Part2" then
        hit.Size = Vector3.new(4,4,4)
    end
end)

script.Parent.TouchEnded:Connect(function(hit)
    if hit.Name == "Part2" then
        hit.Size = Vector3.new(1,4,1)
    end
end)

Hope this helped!

Answer this question