1 | script.Parent.Touched:Connect( function (hit) |
2 |
3 |
4 | hit:FindFirstChild( "humanoid" ) |
5 | print ("PartTouched |
6 |
7 |
8 | end ) |
No errors, it just says part touched when ****Anything**** touches it
Because you have to put hit.Parent:FindFirstChild("humanoid") and also fix print print ("PartTouched)
This one is a bit unclear to me what you're trying to achieve, but if you want to make it so only the Player
can touch the Part
then you can use the :GetPlayerFromCharacter
function.
01 | -- Services |
02 | local playersService = game:GetService( "Players" ) |
03 |
04 | script.Parent.Touched:Connect( function (hit) |
05 | local player = playersService:GetPlayerFromCharacter(hit.Parent) |
06 | if player then |
07 | local character = player.Character |
08 | local humanoid = character:FindFirstChild( "Humanoid" ) |
09 |
10 | print ( "Touched by player..." ) |
11 | end |
12 | end ) |
Your code only has one issue. You didn't use an if statement to check whether the humanoid hits something.
1 | script.Parent.Touched:Connect( function (hit) |
2 |
3 |
4 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
5 |
6 | print ( hit.Parent.Name .. "Has touched the brick" |
7 |
8 | end |
9 | end ) |
Refined grammatical errors. Date: February 19, 2021