Why is my GetTouchingParts script not working?

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it so that the viewmodel can’t go into any parts and if it does then it turns red but if it is not in a part it turns green.

  2. What is the issue? Include screenshots / videos if possible!
    I don’t know much about regions, gettouchingparts or raycasting

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried YT and Devforum

Here’s a picture of my code:

Disabled ClientPlacementFoundation - Roblox Studio 2023_06_09 11_25_38

And here’s a video of what’s happening:

What does v.Name ~= nil and v.Name == nil mean? All parts have a name property and it’s not nil. Your problem is your script waits for a v.Name == nil statement to consider that there are no parts in the way that will never happen, since all parts have a name property set to something. You don’t need loops or anything.
Try this code

local overlap = OverlapParams.new()
local touchingList = workspace:GetPartsInPart(structure, overlap)

if #touchingList > 0 then -- Putting a '#' shows a number of elements in touchingList (in this case - number of parts)
	-- there are some parts in the way
else
	-- there are no parts
end

1 Like

OMG THANKS SO MUCH, I HAVE BEEN TRYING TO DO THIS FOR 2 HOURS!! btw the nil was checking if it wasnt touching a part

1 Like

You probably don’t understand why v.Name == nil isn’t working (and it’s not about that all parts have a name property)

workspace:GetPartsInPart() returns an array of parts in a specified part. That said, you were relying that since there are no parts, v.Name == nil will trigger your code to think that there are no parts. But if there are no parts in part (meaning touchingList is empty), loop wouldn’t even start since there is nothing to go through.

ohh ok, thanks for the info, i will remember that

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.