✓ Accepted answer
Explanation
So, my assumption is that the part that you've welded to the player isn't being touched, and this is why the function isn't working. However, you don't even require the additional welded part.
If we use the CharacterAdded event of the Player Instance (taken from the PlayerAdded event of the Players Service) then we can get the player's character model.
Next, we can use the AncestryChanged event of the model to check that the character is parented under the workspace (which means its parts like the head and humanoidrootpart will have loaded in)
Then we get a table of all BaseParts under the character model and give each of them a .Touched event
Finally, we check that the part is touching a Humanoid with the :FindFirstChild("Humanoid") of what we presume will be a player character model, as well as the :GetPlayerFromCharacter() function of the Players Service to determine that we are not touching a NPC.
Now we can print our statement or perform a function.
Revised Server Script under ServerScriptService
game:GetService("Players").PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(character)
character.AncestryChanged:Connect(function(child, parent)
if parent == workspace then
for i, v in pairs(character:GetDescendants()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
print("Two Players Are Touching!")
end
end)
end
end
end
end)
end)
end)
As you probably already know, you can also add a debounce to prevent further prints for a certain time period.
4 comments
GetPlayerFromCharacter() on the part of the player that hits another player
Is this under a part of the character model?
if something has a humanoid, it isn't always a player
@SerpentineKing yes it's a script placed inside of a part that I have welded to the player.