Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GetTouchingParts not returning the parts intersecting?

Asked by 8 years ago

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

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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.

0
Of course! I forgot to make them collidable! I'll take a look at Region3 too, thank you! Hvxbyte 0 — 8y
0
No problem :) BlackJPI 2658 — 8y
Ad

Answer this question