Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to check a specific part touches another part?

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

1 comment

0

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

2 answers

✓ Accepted answer

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)

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.