script.Parent.Touched:Connect(function(hit) hit:FindFirstChild("humanoid") print("PartTouched 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.
-- Services local playersService = game:GetService("Players") script.Parent.Touched:Connect(function(hit) local player = playersService:GetPlayerFromCharacter(hit.Parent) if player then local character = player.Character local humanoid = character:FindFirstChild("Humanoid") print("Touched by player...") end end)
Your code only has one issue. You didn't use an if statement to check whether the humanoid hits something.
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then print( hit.Parent.Name .. "Has touched the brick" end end)
Refined grammatical errors. Date: February 19, 2021