Help with Not touching parts script

local function GetTouchingParts(part)
	local connection = part.Touched:Connect(function() end)
	local results = part:GetTouchingParts()
	wait(1)
	connection:Disconnect()
	return results
end

local myPart = script.Parent

	while true do
	local touchingParts = GetTouchingParts(myPart) 

	
	for i, v in pairs(touchingParts) do
		if v  then
			script.Parent.Value.Value = true 
			print("Touching Parts")
			
		end
	end
end



while true do
	local Part = script.Parent
	wait(1)
	local Parts = Part:GetTouchingParts()
	
	if not Parts then
	print("Not Touching Parts")
	script.Parent.Value.Value = false
	end
	
	end 

What i’m trying to do i’m trying to make it so that when the block is not touching parts it will change a value to false , The part where it changes it to true works great! I just can’t find out how to make it so that when nothing is touching it, it will change the value

I’m a little bit confused about your approach. Is your only intent to gather whether or not there is at least 1 touching parts?

Yes if theres one part touching then it will change the value and print the Touching Parts, but If theres not parts touching the main part then it should change the value and print Not Touching Parts but for some reason it doesn’t want to print if theres no parts touching it.

Ok! I’d recommend doing this

local function GetTouchingParts(part)
	return part:GetTouchingParts()
end

-------- main
local part = script.Parent
local touching = #GetTouchingParts(part) > 0 --boolean value, true if touching; false if not
1 Like

Try this:

local Part = script.Parent

Part.Touched:Connect(function(Hit)
    print(Hit)
    script.Parent.Value.Value = true
end)

Part.TouchEnded:Connect(function(Hit)
    print(Hit.." has stopped touching")
    script.Parent.Value.Value = false
end)
1 Like

So I would set it up light this correct?

local function GetTouchingParts(part)
	return part:GetTouchingParts()
end

-------- main
local part = script.Parent
local touching = #GetTouchingParts(part) > 0 --boolean value, true if touching; false if not

while true do 
	wait(1)
	if touching == false then
		print("Touching Part")
	else 		
			print("No Touching Part")
	end
end

If you wanna do the loop, do this

local function GetTouchingParts(part)
	return part:GetTouchingParts()
end

-------- main
local part = script.Parent
local touching = #GetTouchingParts(part) > 0 --boolean value, true if touching; false if not

while wait(1) do 
	touching = #GetTouchingParts(part) > 0
    if touching then
       print("Touching part")
    else
       print("No Touching Part")
    end
end

Even when theres a part touching now it says theres not. How can I fix that?

That shouldn’t be happening. If you can attach the .rblx file I can take a look for you, or if you attach a video of the issue you’re having.

Sorry it took so long the video I was trying to upload didn’t want to upload
https://gyazo.com/c24e2cb8322f9f8d5bfbbe4bc547eee7
Edit V

Screen Shot 2022-01-09 at 5.50.19 AM
.Also this is how it’s set up. Ignore the other 2 scripts those are from past test.

I found out that if I turn on can collide on it works, but I can’t have that cause then the plane will get stuck.

Alright I figured it out heres the ending code

local function GetTouchingParts(part)
	local connection = part.Touched:Connect(function() end)
	local results = part:GetTouchingParts()
	wait(1)
	connection:Disconnect()
	return results
end

-------- main
local part = script.Parent
local touching = #GetTouchingParts(part) > 0 --boolean value, true if touching; false if not

while wait(1) do 
	touching = #GetTouchingParts(part) > 0
	if touching then
		print("Touching part")
	else
		print("No Touching Part")
	end
end
1 Like