Detecting the player who touched a part

Hi, i’m trying to make it so that if the door was touched by a player, it will return who touched it. How would I go about doing that?

3 Likes

The Touched event passes the object that came in contact as a parameter, just use that.

thing.Touched:Connect(
    function(touch)
        if touch.Parent:FindFirstChild("Humanoid") then
            local char = touch.Parent
            local player = game:GetService("Players"):GetPlayerFromCharacter(char)
            print("Your name is : " .. player.Name)
        end
    end
)
19 Likes