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.
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.
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
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.
This is a very bad example. You didn't check to see if the hit had a humanoid. This could definitely backfire.
Alright let me fix it.. :/
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
Thank you so much, the first was so useful!!
Tried the script, doesn't work...
Nvm, works perfectly! I'm so happy, thanks so much!!!