Terrain Cannot Get Touching Parts

I’m making a script that, after a certain amount of seconds pass by, resets terrain to restore it when players destroy it. However, the terrain is a large block, so if players dig a hold inside it, go in the hole when it’s resetting, players will be inside the terrain. My game is a fighting game, so players will be fully protected while in the terrain. They can freely move in the terrain, and have no trouble simply walking out of it, but they would still be protected while inside it. I’m trying to prevent this by teleporting players outside of the terrain when they are in it, however I am having some issues with this.

I’m trying to call :GetTouchingParts() on the terrain, but it errors, saying that it is not a valid member of terrain.

This is the script. It is in ServerScriptService.

local terrain = game.Workspace.Terrain
local origin = game.Workspace.TerrainOrigin
local teleport = game.Workspace.TerrainTeleport

terrain:Clear()
terrain:FillBlock(origin.CFrame, Vector3.new(104, 104, 104), Enum.Material.Pavement)

while true do
	wait(10)
	local parts = terrain:GetTouchingParts()
    for index, part in pairs(parts) do
        if part.Name == "HumanoidRootPart" then
            part.Parent:MoveTo(teleport.Position)
        end
    end
	terrain:Clear()
	terrain:FillBlock(origin.CFrame, Vector3.new(104, 104, 104), Enum.Material.Pavement)
end
  1. What do you want to achieve? I want to teleport players out of the terrain if they’re inside of it.

  2. What is the issue? I cannot call :GetTouchingParts() on the terrain to do this.

  3. What solutions have you tried so far? I tried searching for similar topics about my issue, but could not find anything that could help. I also looked at the Developer Hub, but according to that, :GetTouchingParts() is a valid member of terrain.

Additionally, I tried to make a separate part that takes the shape of the terrain, and call :GetTouchingParts() on that, but the problem with that is that my game makes use of the player’s mouse to destroy terrain, and the part would prevent the player from destroying the terrain.

You can use Humanoid | Documentation - Roblox Creator Hub to find out if a player is standing on terrain. This probably works to check if the player is inside it too, however I’m not completely sure.

Alternatively, if above doesn’t work, you can raycast up and down to get a fairly accurate reading on when a player is on or in terrain.

3 Likes

If the terrain is just floor without any ceilings, you can raycast down from the sky to try and find the lowest point in terrain to be spawned on. Also, you can always just use MoveTo which automatically places the model up ontop of any parts and terrain in its way.

I recommend the raycasting approach mentioned above by jojo2467. The problem with getTouchingParts is that it’s computationally expensive and even if you got it to work with terrain (which you won’t because you need a TouchInterest), it would probably lag your game pretty hard while it checks every vertex of terrain against the parts in your world.

If you try to use a nonexistent property or method name on an Instance there will be an error message that concatenates the property name with is not a valid member of and then concatenates the Instance name.

However I noted that the Roblox Studio binary contains the string GetTouchingParts is not a valid member of Terrain which means it is explicitly hardcoded to not allow GetTouchingParts on Terrain.

By the way the is not a valid member of error is only thrown when indexing an item, but you can index Terrain with 'GetTouchingParts' just fine, but you just cannot call the method on Terrain.