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

What alternatives for Touched allow one brick to be detected by another?

I need this really badly... I don't want terrain to detect player interaction - in fact I want no player interaction whatsoever. I need a script that works like OnTouch but for parts instead of players.

Does such a thing even exist?

Please help me.

2 answers

From what I understand of your question you are attempting to detect collision between two parts, this can be done using the GetTouchingParts method, here is an example of this:

for _, v in pairs(Part:GetTouchingParts()) do
	print(v) -- v is one of the parts colliding with your original part.
end

Keep in mind that this method will return a table filled with every part that intersects the original part in question that has it's CanCollide property set to true.

Just in-case I've misinterpreted this question and you're actually after an event for when the player touches the brick, then this can be done like so:

local Part = game.Workspace.Part

Part.Touched:connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") ~= nil then
		local Character 	= 	Hit.Parent
		local Player 		=	game.Players:GetPlayerFromCharacter(Character)
	end
end

3 comments

0

Thank you so much, the first was so useful!!

0

Tried the script, doesn't work...

0

Nvm, works perfectly! I'm so happy, thanks so much!!!

Yes, this is possible. It's very simple. In a script, you need to make sure it detects the part and only run the function if whatever touches is a part, rather than a player.

Here is an example script. I tested it with R15 and it works fine.

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then --Checks if touched is a player.
		--Code or just leave blank.
	else
		script.Parent.BrickColor = BrickColor.new("Forest green") --If anything else, like a part, then make the color green.
	end
end)

EDIT: Fixed the script.

2 comments

0

This is a very bad example. You didn't check to see if the hit had a humanoid. This could definitely backfire.

0

Alright let me fix it.. :/

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