script.Parent.Touched:Connect(function(hit)
hit:FindFirstChild("humanoid")
print("PartTouched
end)
No errors, it just says part touched when Anything touches it
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)
Please use a code block, you'd also need an if statement to check wether a character model hits a brick.
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
If you have anymore messages, feel free to message me.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Make sure you used an if statement. If hit.Parent:FindFirstChild("Humanoid")