Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 6 years ago

Title says it all, idk what to put here xd

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. CodyDev 70 — 6y

1 answer

Log in to vote
3
Answered by
CPF2 406 Moderation Voter
6 years ago

: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()
Ad

Answer this question