PlayerRemoving structure

Hi, I’m just wondering if this is a viable way to use PlayerRemoving:

game.Players.PlayerAdded:Connect(function(plr)
    game.Players.PlayerRemoving:Connect(function(player)
        if player == plr then
            --code here
        end
    end)
end)

Or should these two functions be entirely separate?

I’m thinking about using this so I don’t have to call :GetAsync() on my datastore twice in two separate functions. What if :GetAsync() doesn’t fail on PlayerAdded, but it fails on PlayerRemoving?

The two functions should be separate, as they are independent events.

Could you elaborate on what you mean by calling GetAsync twice? If you’re saving player data, GetAsync should only be called once on join and SetAsync/UpdateAsync on leave

1 Like