So I'm working on a game where I need stuff to happen when a player joins, dies or respawns. The way I though of doing it was through some events and functions all running for a ServerScript in ServerScriptStorage, something like this:

--ServerScript in ServerScriptStorage
local function onPlayerAdded(player)
    local function onCharacterAdded(character)
	    local function onCharacterDied()
		    --So some stuff
		end
		--Do some stuff
		character:WaitForChild("Humanoid").Died:Connect(onCharacterDied)
	end
	--Do some DataStore stuff
	--Do some more stuff
	player.CharacterAdded:Connect(onCharacterAdded)
end
game.Players:PlayerConnecting:Connect(onPlayerAdded)

So I was wondering if this would work all right, or if there is a better/more elegant way to do this.

Thanks :D