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

how do you use GetTouchedParts properly?

My GetTouchingParts script suddenly doesnt work anymore, but I probably messed it up, so I made something in a new game, a part named test touches two other parts, named part. This is the code I used:

local test = game.Workspace.test

for i,v in pairs(test:GetTouchingParts())do
	print(v.Name.." touched")
end
for i,v in pairs(test:GetConnectedParts())do
	print(v.Name.." connected")
end

and this is the output I got:

test connected Part connected (x2)

Can anyone tell me what I did wrong here?

2 comments

0

What are you trying to accomplish with that script?

0

I just want it to tell what parts it is touching, I can get them with connectedparts, but then test itself is in the table

1 answer

Edit1

local test = game.Workspace.test
local PartsTouched = {} -- create a table

for i,part in pairs(test:GetConnectedParts()) do
	if not part.Name == test.Name then
		table.insert(PartsTouched, part) -- add the part to our table
	end
end

for i,part in pairs(PartsTouched) do
	print(part.Name .. " connected.") -- print the table
end

This should print every part connected but the test¨part itself.

2 comments

0

it doesnt print anything, if I delete the if statement, it prints everything

0

does it work now?

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