Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What does :Wait() and :Disconnect() do and when should I use it?

Title says it all, idk what to put here xd

2 comments

0

You probably wouldn't ever need to use :Disconnect(). It disconnects an event connection and I can only imagine that to be useless. :Wait() waits for an event to happen or waits a number of seconds before continuing to the next line in the script.

1 answer

✓ Accepted answer

:Wait() yields until an event happens, so if you did something like

local character = player.Character or player.CharacterAdded:Wait()

It would set the character variable as the character of the player, or wait until the player's character finishes loading, then it would set the variable.

As for :Disconnect(), it disconnects a function you set to run when an event fires, ex.

local part = Instance.new('Part')

local function onPartTouched(hit)
	-- script
end

local connection = part.Touched:Connect(onPartTouched)

connection:Disconnect()

This discussion is preserved as it was. New answers, comments, and votes are closed.