Help with :GetTouchingParts()

Good evening,

I need a little help using :GetTouchingParts().

local function two()
	while true do
		for i,v in pairs(game.Workspace.Tiles:GetChildren()) do
			v.CanCollide = true
			local touchingparts = v:GetTouchingParts()
			for index, value in ipairs(touchingparts) do
				if value.Parent:IsA("Model") and value.Parent:FindFirstChild("Humanoid") then
					local player = value.Parent:GetPlayerFromCharacter(value.Parent)
					v.BrickColor = player.Color.Color.Value
				end
			end
		end
		wait(0.1)
	end
end

coroutine.resume(coroutine.create(two))

This doesn’t work, but it doesn’t show any errors. I’m sure that my mistake is simple and easy to fix, for this is the first time that I have used :GetTouchingParts().

1 Like

All parts returned with BasePart:GetTouchingParts must have a .Touched event connected to them. I would just connect a touched event with an empty function on all of the parts that you need to check against. Do be careful with how many of these you create though!

EDIT: My bad! It’s all CanCollide = false parts, not all parts!

2 Likes
local player = value.Parent:GetPlayerFromCharacter(value.Parent)

Change this to:

local player = game.Players:GetPlayerFromCharacter(value.Parent)
1 Like

It works, however, it’s super slow. Plus, only the wall tiles change colors, not the floor tiles.

1 Like

You are getting the player that touched it right? R15 Character’s Feet are cancollide false so the GetTouchingParts() wouldnt work and R6 Character’s legs are cancollide false so again, GetTouchingParts() wont work

1 Like

So how do I fix it?

30 Characters.

1 Like

You can use region3, and check the parts that are in it

1 Like

How would I implement that into my code?

1 Like

Sorry if I’m wrong, but don’t you need to only attach a .Touched event if the part the function is being called from is CanCollide false?

2 Likes

well first you would create the region3 where you want it, which im guessing it will be in or on the Tile, then in a loop you would do something like

local Hit = workspace:FindPartsInRegion3WithIgnoreList(TheRegion3,{},1)

then check if Hit is part of a players character

1 Like

Except cancollide is true. {30CHAR}

1 Like

It says here that you only need the .Touched event if the part is CanCollide false. If it’s CanCollide true, there should be no issue.

1 Like

for default roblox Characters, all the limbs are CanCollide false except UpperTorso,LowerTorso,Head,Torso,and HumanoidRootPart

1 Like

You could use .Touched for the parts, but im saying GetTouchingParts() Only returns parts that collide with it, so if the character walks on a tile, its not going to return the part of the character that touched it because their feet are CanCollide false, if the Tile is CanCollide false then nothing can collide with it so that wouldnt work

He had it in a loop so I just assumed he wanted it to be in a loop for a reason, so I recommended using Region3

1 Like
local function two()
	while true do
		for i,v in pairs(game.Workspace.Tiles:GetChildren()) do
			v.CanCollide = true
			local touchingparts = v:GetTouchingParts()
			for index, value in ipairs(touchingparts) do
				local Hit = workspace:FindPartsInRegion3WithIgnoreList(v,{},1)
				if Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChild("Humanoid") then
					local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
					print(player)
					v.BrickColor = player.Color.Color.Value
				end
			end
		end
		wait(0.1)
	end
end

coroutine.resume(coroutine.create(two))

@bronsonman Revised code above still doesn’t work. What did I do wrong?

1 Like

are you sure you created the Region3 correctly

If you did want to use GetTouchingParts() then if a part has a TouchInterest, then it will work even if its CanCollide false

1 Like

oo my bad, you have to create the region3 in the loop, sorry about that

1 Like

what type of loop?

30 Characters

1 Like

the loop you have is fine

im typing this for 30 characters

1 Like

okay sorry again, you dont have to have it in a loop, my brain is just not functioning correctly right now, just make sure you created the region3 in the correct spot

1 Like