Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

my part wont print "PartTouched" when touched(By humanoid)?


script.Parent.Touched:Connect(function(hit)
	
	
	hit:FindFirstChild("humanoid")
	print("PartTouched

	
end)

No errors, it just says part touched when Anything touches it

1 comment

1

Make sure you used an if statement. If hit.Parent:FindFirstChild("Humanoid")

3 answers

Because you have to put hit.Parent:FindFirstChild("humanoid") and also fix print print ("PartTouched)

1 comment

0

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

1 comment

0

If you have anymore messages, feel free to message me.

This discussion is preserved as it was. New answers, comments, and votes are closed.