How Do I Wait Till A Function Connects

Hello I want To Run Something as soon as a player joins but i need to wait a bit so the function connects, i can try wait(1) but it may take more than 1 sec to connect is there a way to wait

thank you

3 Likes

There is a method called Wait which stops the thread from continuing until the signal fires

Event:Wait() -- replace this with the function you wanna wait for
1 Like

I got an error

Wait is not a valid member of RemoteEvent "ReplicatedStorage.CameraFocus"

1 Like

Mb, that has to be an RBXScriptSignal. (something like .Touched)
so as an example:

part.Touched:Wait()
1 Like

You are attempting to call the Wait() on an instance, it is only exposed by RBXScriptSignals so for a RemoteEvent that would be RemoteEvent.OnServerEvent or RemoteEvent.OnClientEvent.

There is a built in function that let’s you know when a player has joined the game:

ReplicatedStorage.CameraFocus.OnServerEvent:Wait() as @NinjaFurfante07 mentioned