Hey, i was trying to add a wait() inside a function, before it does the other stuff, And it just completely ignored the wait() and prints. i also tried using task.wait()
local function updateCamera(playerSubject)
playerSubject.Character:WaitForChild("Humanoid").Died:Connect(function()
wait(4)
print("spectating player died")
end)
end
yes i did call the function, everything works, its just that the wait is ignored.
this is the full code
local function updateCamera(playerSubject)
playerSubject.Character:WaitForChild("Humanoid").Died:Connect(function()
wait(4)
print("spectating player died")
end)
pcall(function()
spectateFrame.Nametext.Text = tostring(playerSubject)
cam.CameraSubject = playerSubject.Character
end)
end
That’s because that’s an event listener. Once the Humanoid.Died gets fired, the function gets called since there is a wait for 4 seconds. It would wait and then print “spectating player died”. Unless the print() function is called in an instant. Since there is a wait, that’s unlikely. You could try this to see if the wait is actually working.
local start = os.clock()
task.wait(4)
print(start - os.clock())
print("spectating player died")
Also wait is not safe to use there would be a time where this wait 4 seconds could actually be greater than 4 seconds. task.wait is safer to use since this is being handled by the task scheduler.