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

GetTouchingParts not returning the parts intersecting?

Okay; so I'm working on a strategy game revolved around territorial control, and upon a player's join, a capital will be created for them, if it doesn't already exist... now, given that the capital spawns, it's supposed to check if any 'Fog of War' parts intersect with the territory itself, if so, destroy them... I've even tried printing the name of the connected parts, and it merely prints the player's capital.

local function createCapital(player)
	if checkMap() == true and game.Workspace:FindFirstChild(player.Name .. "'s Capital") == nil then
		local capital = Instance.new("Part", game.Workspace);
		capital.Name = player.Name .. "'s Capital";
		capital.BrickColor = BrickColor.new(player.TeamColor.Name);
		capital.FormFactor = Enum.FormFactor.Custom;
		capital.Size = Vector3.new(1, 0.25, 1);
		capital.Anchored = true;
		capital.Material = Enum.Material.Slate;
		local territory = selectTerritory(game.Workspace:FindFirstChild("Map"));
		territory:WaitForChild("Fog of War"):Destroy();
		territory.BrickColor = capital.BrickColor;
		capital.CFrame = CFrame.new(territory.Position) * CFrame.new(0, 0.25, 0);
		local mesh = Instance.new("CylinderMesh", capital);
		local capitalized = Instance.new("BoolValue", territory);
		capitalized.Name = "Capitalized";
		capitalized.Value = true;
		wait(1);
		for _, connected in next, territory:GetTouchingParts() do
			if connected.Name == "Fog of War" then
				connected:Destroy();
			end
		end
	end
end

1 answer

I'm assuming the 'Fog of War' parts have their CanCollide properties set to false.

The function GetTouchingParts return a table of all collidable parts intersecting the given part. Because 'Fog of War' parts are not collidable, they do not show up in the list.

You could write a function that sets the CanCollide property to true for all the 'Fog of War' parts, or use the function FindPartsInRegion3. I will show you a solution for the latter of the suggestions.

Region3 Solution

The solution is pretty straight forward, so I'll just leave this documentation here for reference.

local StartPoint = territory.Position - territory.Size/2
local EndPoint= territory.Position + territory.Size/2
local Region3 = Region3.new(StartPoint, EndPoint)

for _, part in ipairs (game.Workspace:FindPartsInRegion3(Region3, nil, 100)) do
	if part.Name == "Fog of War" then
		part:Destroy()
	end
end

Post any questions or concerns in the comments below.

2 comments

0

Of course! I forgot to make them collidable! I'll take a look at Region3 too, thank you!

0

No problem :)

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