Is there a way to make a Touched event wait to fire?

I found a way but i have a problem:

Example~1:

local Part = script.Parent

Part.Touched:Wait(5) -- how do I see who touched it?
Print("WhouTouched")

As shown in example 1 it is how I wanted it, BUT, how do I see who touched it?
Any way to connect a function to the wait? or see who touched
As shown in the example below

Example~2:

local Part = script.Parent

Part.Touched:Connect(function(WhoTouched)
Print(WhouTouched)
end)

Just add a wait() statement into the connected function.

local Part = script.Parent

Part.Touched:Connect(function(WhoTouched)
   wait(5)
   Print(WhouTouched)
end)

The easiest way would be to use GetPlayerFromCharacter

local touchedPart = Part.Touched:Wait()
local player = Players:GetPlayerFromCharacter(touchedPart.Parent)
print(player)

You can find more about it here

local Part = script.Parent
local Players = game:GetService("Players")

local touchedPart = Part.Touched:Wait()
local player = Players:GetPlayerFromCharacter(touchedPart.Parent)
print(player)

Returned nil

It’s most likely because an accessory touched the part, or another part touched it first. You can try using FindFirstAncestorOfClass

local Part = script.Parent
local Players = game:GetService("Players")

local touchedPart = Part.Touched:Wait()
local model = touchedPart:FindFirstAncestorOfClass("Model")
if model then
    local player = Players:GetPlayerFromCharacter(model)
    print(player)
end

Do player.Name, player itself will return nil I believe

image

I take that back, I’ve just tested this script

and it worked perfectly.


Screen Shot 2021-03-09 at 7.56.46 PM

local Part = script.Parent

Part.Touched:Connect(function(stuff)
wait(math.huge) -- math.huge is infinite anyways
print(stuff.Name)
end)

make sure it has a humanoid on the parent