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

trying to get a nil value when using GetTouchingParts()?

script.Parent.Touched:Connect(function()end)

  

while true do

wait(1)

local part = script.Parent

local bounds = part:GetTouchingParts()

for _, p in next, bounds do

  

if p == nil then

print("nothing")

end

end

end

this script gets the parts that are inside it using GetTouchingParts() I was trying to get it to output nil when there is nothing touching but it wont throw an error or say nil when there is nothing inside it. this is a problem because I need to be able to do something else when a specific part/model that "was" touching is now gone. is there a way to make this as easy as using FindFirstChild() to get a nil value?(findfirstchild didnt work when I combined it btw)

1 comment

0

What is it printing then if it's not printing nil?

1 answer

delete the end) after connect(function() and put a ) at the last line ur not connecting the function right now

here is what i mean u should do

script.Parent.Touched:Connect(function()

  

while true do

wait(1)

local part = script.Parent

local bounds = part:GetTouchingParts()

for _, p in next, bounds do

  

if p == nil then

print("nothing")

end

end

end)

1 comment

0

to answer both comments within the last 6 hours, the script did not print anything when ran. and also:https://devforum.roblox.com/t/simple-trick-to-make-gettouchingparts-work-with-non-cancollide-parts/177450 this is why I have gettouchingparts set u pthe way it is as it will not work without it.

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