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

When you put a player on connect method, does it hold?

Does it hold the player forever until he leaves the server? For example When a player connects, he gets the event fired... Does the event hold that player forever until he leaves the server? Or...how does it work?

2 answers

Depends on the event, the PlayerAdded event will hold the player until he leaves, the CharacterAdded will hold the Character until it is removed (the player dies or is respawned). The touched event will hold the part for as long as you want, but I assume you are referring to the PlayerAdded command which fires once when the player joins and is used mainly for setting up the player (leaderstats, chatted events, character added and removing events).

To add onto crackabottle's answer, if you want a connection to no longer apply to an object, you can disconnect it. The connect method returns a RbxScriptConnection that contains a disconnect method. For example-

local connection 
connection = Part.Touched:connect(function(hit)
	print("Touched")
	if hit.Parent.Name == "Player1" then -- if a character with the name of Player1 hits it, then
		connection:disconnect() -- disconnect the connection, meaning "Touched" won't be printed anymore when the Part is touched
	end
end)

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