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

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

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

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).

Ad
Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
10 years ago

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)

Answer this question