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.
What is the issue? Include screenshots / videos if possible!
I don’t know much about regions, gettouchingparts or raycasting
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried YT and Devforum
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
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.