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

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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
0
Thank you so much, the first was so useful!! MisterMCCreeper -4 — 7y
0
Tried the script, doesn't work... MisterMCCreeper -4 — 7y
0
Nvm, works perfectly! I'm so happy, thanks so much!!! MisterMCCreeper -4 — 7y
Ad
Log in to vote
-1
Answered by
Mayk728 855 Moderation Voter
7 years ago
Edited 7 years ago

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.

0
This is a very bad example. You didn't check to see if the hit had a humanoid. This could definitely backfire. AstrealDev 728 — 7y
0
Alright let me fix it.. :/ Mayk728 855 — 7y

Answer this question