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

how do you use GetTouchedParts properly?

Asked by 6 years ago

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?

0
What are you trying to accomplish with that script? Le_Teapots 913 — 6y
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 saveourwolves 2 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
it doesnt print anything, if I delete the if statement, it prints everything saveourwolves 2 — 6y
0
does it work now? Le_Teapots 913 — 6y
Ad

Answer this question